gpt4 book ai didi

java - 调用时收集 NoSuchMethodError,stream() 方法

转载 作者:太空宇宙 更新时间:2023-11-03 12:30:03 24 4
gpt4 key购买 nike

  public int getColsBy(final Collection<Room> rooms) {
return rooms.stream()
.max((lhs, rhs) -> lhs.right - rhs.right).get().right;
}

我尝试在我的 libgdx 项目中执行这段代码,但我只有异常!

04-15 22:34:21.136 32610-32636/com.mygdx.game E/AndroidRuntime: FATAL EXCEPTION: GLThread 8116
Process: com.mygdx.game, PID: 32610
java.lang.NoSuchMethodError: No interface method stream()Ljava/util/stream/Stream; in class Ljava/util/Collection; or its super classes (declaration of 'java.util.Collection' appears in /system/framework/core-libart.jar)
at com.mygdx.game.enviroment.LevelParser.getColsBy(LevelParser.java:44)
at com.mygdx.game.enviroment.LevelParser.parseFrom(LevelParser.java:30)
at com.mygdx.game.MyGdxGame.create(MyGdxGame.java:38)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:243)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1550)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1272)

有我的build.gradle文件

   buildscript {
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
}
dependencies {
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
classpath 'com.android.tools.build:gradle:2.1.0-beta1'
classpath 'org.robovm:robovm-gradle-plugin:1.12.0'
classpath 'me.tatarka:gradle-retrolambda:3.3.0-beta4'
classpath 'me.tatarka.retrolambda.projectlombok:lombok.ast:0.2.3.a2'
configurations.classpath.exclude group: 'com.android.tools.external.lombok'
}
}

allprojects {
apply plugin: "eclipse"
apply plugin: "idea"

version = '1.0'
ext {
appName = "my-gdx-game"
gdxVersion = '1.7.2'
roboVMVersion = '1.12.0'
box2DLightsVersion = '1.4'
ashleyVersion = '1.7.0'
aiVersion = '1.7.0'
}

repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}

project(":desktop") {
apply plugin: "java"


dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
}
}

project(":android") {
apply plugin: "android"
apply plugin: "com.android.application"
apply plugin: "me.tatarka.retrolambda"

configurations { natives }

dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
}

}

project(":ios") {
apply plugin: "java"
apply plugin: "robovm"


dependencies {
compile project(":core")
compile "org.robovm:robovm-rt:$roboVMVersion"
compile "org.robovm:robovm-cocoatouch:$roboVMVersion"
compile "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"
}
}

project(":html") {
apply plugin: "gwt"
apply plugin: "war"


dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
compile "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
}
}

project(":core") {
apply plugin: "java"
apply plugin: "me.tatarka.retrolambda"

dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
}
}

tasks.eclipse.doLast {
delete ".project"
}

我应该做什么才能在我的项目中使用流?

最佳答案

有些事你可以做。 Android 从版本 7 (Nougat) 开始支持 Java 8。

(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) 包围您的流 api 调用

public int getColsBy(final Collection<Room> rooms) {

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return rooms.stream().max((lhs, rhs) -> lhs.right - rhs.right).get().right;
}else{
return "max the old fashion way"
}
}

我不喜欢外部库,而这就是我所做的。

关于java - 调用时收集 NoSuchMethodError,stream() 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36652633/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com