gpt4 book ai didi

java - 大多数基本的 libgdx 应用程序崩溃

转载 作者:行者123 更新时间:2023-11-30 01:25:07 26 4
gpt4 key购买 nike

我准备在 Windows 10、最新的 Eclipse Mars.2、最新的 Android SDK 和最新版本的 libGDX 上开发 libGDX And​​roid 应用程序。我正在按照此处的设置说明进行操作: Project Setup Gradle

这里:

Setting up your Development Environment (Eclipse, Intellij IDEA, NetBeans)

这里

Gradle and Eclipse

当我运行我的 android 应用程序时,它崩溃并在 logcat 中输出:

04-09 02:01:56.357: E/Trace(20747): error opening trace file: No such file or directory (2)
04-09 02:01:56.367: D/ActivityThread(20747): setTargetHeapUtilization:0.25
04-09 02:01:56.367: D/ActivityThread(20747): setTargetHeapIdealFree:8388608
04-09 02:01:56.367: D/ActivityThread(20747): setTargetHeapConcurrentStart:2097152
04-09 02:01:56.548: W/dalvikvm(20747): Unable to resolve superclass of Lcom/mygdx/game/AndroidLauncher; (3)
04-09 02:01:56.548: W/dalvikvm(20747): Link of class 'Lcom/mygdx/game/AndroidLauncher;' failed
04-09 02:01:56.548: W/dalvikvm(20747): threadid=1: thread exiting with uncaught exception (group=0x41367438)
04-09 02:01:56.568: E/AndroidRuntime(20747): FATAL EXCEPTION: main
04-09 02:01:56.568: E/AndroidRuntime(20747): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mygdx.game/com.mygdx.game.AndroidLauncher}: java.lang.ClassNotFoundException: com.mygdx.game.AndroidLauncher
04-09 02:01:56.568: E/AndroidRuntime(20747): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2005)
04-09 02:01:56.568: E/AndroidRuntime(20747): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2106)
04-09 02:01:56.568: E/AndroidRuntime(20747): at android.app.ActivityThread.access$600(ActivityThread.java:138)
04-09 02:01:56.568: E/AndroidRuntime(20747): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1204)
04-09 02:01:56.568: E/AndroidRuntime(20747): at android.os.Handler.dispatchMessage(Handler.java:99)
04-09 02:01:56.568: E/AndroidRuntime(20747): at android.os.Looper.loop(Looper.java:137)
04-09 02:01:56.568: E/AndroidRuntime(20747): at android.app.ActivityThread.main(ActivityThread.java:4921)
04-09 02:01:56.568: E/AndroidRuntime(20747): at java.lang.reflect.Method.invokeNative(Native Method)
04-09 02:01:56.568: E/AndroidRuntime(20747): at java.lang.reflect.Method.invoke(Method.java:511)
04-09 02:01:56.568: E/AndroidRuntime(20747): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
04-09 02:01:56.568: E/AndroidRuntime(20747): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
04-09 02:01:56.568: E/AndroidRuntime(20747): at dalvik.system.NativeStart.main(Native Method)
04-09 02:01:56.568: E/AndroidRuntime(20747): Caused by: java.lang.ClassNotFoundException: com.mygdx.game.AndroidLauncher
04-09 02:01:56.568: E/AndroidRuntime(20747): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
04-09 02:01:56.568: E/AndroidRuntime(20747): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-09 02:01:56.568: E/AndroidRuntime(20747): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-09 02:01:56.568: E/AndroidRuntime(20747): at android.app.Instrumentation.newActivity(Instrumentation.java:1056)
04-09 02:01:56.568: E/AndroidRuntime(20747): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1996)
04-09 02:01:56.568: E/AndroidRuntime(20747): ... 11 more

知道我做错了什么吗?

这是我的 android 代码,未更改并由 libGDX 设置过程生成。

package com.mygdx.game;

import android.os.Bundle;

import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.mygdx.game.MyGdxGame;

public class AndroidLauncher extends AndroidApplication {
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new MyGdxGame(), config);
}
}

这是我的 AndroidManifest.xml(同样完全没有改变)

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mygdx.game"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="23" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/GdxTheme" >
<activity
android:name="com.mygdx.game.AndroidLauncher"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

这里是android目录下的gradle.build,也是我没改的。

android {
buildToolsVersion "23.0.3"
compileSdkVersion 23
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}

instrumentTest.setRoot('tests')
}
defaultConfig {
applicationId "com.mygdx.game"
minSdkVersion 8
targetSdkVersion 23
}
}


// called every time gradle gets executed, takes the native dependencies of
// the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK.
task copyAndroidNatives() {
file("libs/armeabi/").mkdirs();
file("libs/armeabi-v7a/").mkdirs();
file("libs/arm64-v8a/").mkdirs();
file("libs/x86_64/").mkdirs();
file("libs/x86/").mkdirs();

configurations.natives.files.each { jar ->
def outputDir = null
if(jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")
if(jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")
if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
if(jar.name.endsWith("natives-x86_64.jar")) outputDir = file("libs/x86_64")
if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
if(outputDir != null) {
copy {
from zipTree(jar)
into outputDir
include "*.so"
}
}
}
}

task run(type: Exec) {
def path
def localProperties = project.file("../local.properties")
if (localProperties.exists()) {
Properties properties = new Properties()
localProperties.withInputStream { instr ->
properties.load(instr)
}
def sdkDir = properties.getProperty('sdk.dir')
if (sdkDir) {
path = sdkDir
} else {
path = "$System.env.ANDROID_HOME"
}
} else {
path = "$System.env.ANDROID_HOME"
}

def adb = path + "/platform-tools/adb"
commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.mygdx.game/com.mygdx.game.AndroidLauncher'
}

// sets up the Android Eclipse project, using the old Ant based build.
eclipse {
// need to specify Java source sets explicitly, SpringSource Gradle Eclipse plugin
// ignores any nodes added in classpath.file.withXml
sourceSets {
main {
java.srcDirs "src", 'gen'
}
}

jdt {
sourceCompatibility = 1.6
targetCompatibility = 1.6
}

classpath {
plusConfigurations += [ project.configurations.compile ]
containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'
}

project {
name = appName + "-android"
natures 'com.android.ide.eclipse.adt.AndroidNature'
buildCommands.clear();
buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder"
buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder"
buildCommand "org.eclipse.jdt.core.javabuilder"
buildCommand "com.android.ide.eclipse.adt.ApkBuilder"
}
}

// sets up the Android Idea project, using the old Ant based build.
idea {
module {
sourceDirs += file("src");
scopes = [ COMPILE: [plus:[project.configurations.compile]]]

iml {
withXml {
def node = it.asNode()
def builder = NodeBuilder.newInstance();
builder.current = node;
builder.component(name: "FacetManager") {
facet(type: "android", name: "Android") {
configuration {
option(name: "UPDATE_PROPERTY_FILES", value:"true")
}
}
}
}
}
}
}

如果我尝试在调试器中运行该应用程序,我会在尝试跨过第一条指令时立即在 logcat 中获取此信息:

04-09 19:23:54.285: D/AndroidRuntime(2419): Shutting down VM
04-09 19:23:54.286: E/AndroidRuntime(2419): FATAL EXCEPTION: main
04-09 19:23:54.286: E/AndroidRuntime(2419): Process: com.mygdx.game, PID: 2419
04-09 19:23:54.286: E/AndroidRuntime(2419): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mygdx.game/com.mygdx.game.AndroidLauncher}: java.lang.ClassNotFoundException: Didn't find class "com.mygdx.game.AndroidLauncher" on path: DexPathList[[zip file "/data/app/com.mygdx.game-1/base.apk"],nativeLibraryDirectories=[/data/app/com.mygdx.game-1/lib/x86_64, /data/app/com.mygdx.game-1/base.apk!/lib/x86_64, /vendor/lib64, /system/lib64]]
04-09 19:23:54.286: E/AndroidRuntime(2419): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
04-09 19:23:54.286: E/AndroidRuntime(2419): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
04-09 19:23:54.286: E/AndroidRuntime(2419): at android.app.ActivityThread.-wrap11(ActivityThread.java)
04-09 19:23:54.286: E/AndroidRuntime(2419): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
04-09 19:23:54.286: E/AndroidRuntime(2419): at android.os.Handler.dispatchMessage(Handler.java:102)
04-09 19:23:54.286: E/AndroidRuntime(2419): at android.os.Looper.loop(Looper.java:148)
04-09 19:23:54.286: E/AndroidRuntime(2419): at android.app.ActivityThread.main(ActivityThread.java:5417)
04-09 19:23:54.286: E/AndroidRuntime(2419): at java.lang.reflect.Method.invoke(Native Method)
04-09 19:23:54.286: E/AndroidRuntime(2419): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
04-09 19:23:54.286: E/AndroidRuntime(2419): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
04-09 19:23:54.286: E/AndroidRuntime(2419): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mygdx.game.AndroidLauncher" on path: DexPathList[[zip file "/data/app/com.mygdx.game-1/base.apk"],nativeLibraryDirectories=[/data/app/com.mygdx.game-1/lib/x86_64, /data/app/com.mygdx.game-1/base.apk!/lib/x86_64, /vendor/lib64, /system/lib64]]
04-09 19:23:54.286: E/AndroidRuntime(2419): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
04-09 19:23:54.286: E/AndroidRuntime(2419): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
04-09 19:23:54.286: E/AndroidRuntime(2419): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
04-09 19:23:54.286: E/AndroidRuntime(2419): at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
04-09 19:23:54.286: E/AndroidRuntime(2419): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
04-09 19:23:54.286: E/AndroidRuntime(2419): ... 9 more
04-09 19:23:54.286: E/AndroidRuntime(2419): Suppressed: java.lang.NoClassDefFoundError: com.mygdx.game.AndroidLauncher
04-09 19:23:54.286: E/AndroidRuntime(2419): at dalvik.system.DexFile.defineClassNative(Native Method)
04-09 19:23:54.286: E/AndroidRuntime(2419): at dalvik.system.DexFile.defineClass(DexFile.java:226)
04-09 19:23:54.286: E/AndroidRuntime(2419): at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
04-09 19:23:54.286: E/AndroidRuntime(2419): at dalvik.system.DexPathList.findClass(DexPathList.java:338)
04-09 19:23:54.286: E/AndroidRuntime(2419): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
04-09 19:23:54.286: E/AndroidRuntime(2419): ... 13 more
04-09 19:23:54.286: E/AndroidRuntime(2419): Suppressed: java.lang.ClassNotFoundException: com.mygdx.game.AndroidLauncher
04-09 19:23:54.286: E/AndroidRuntime(2419): at java.lang.Class.classForName(Native Method)
04-09 19:23:54.286: E/AndroidRuntime(2419): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
04-09 19:23:54.286: E/AndroidRuntime(2419): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
04-09 19:23:54.286: E/AndroidRuntime(2419): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
04-09 19:23:54.286: E/AndroidRuntime(2419): ... 12 more
04-09 19:23:54.286: E/AndroidRuntime(2419): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

最佳答案

默认情况下,您的 libgdx Assets “badlogic.jpg”位于“project_direcotry/android/assets”。

当您没有正确设置工作目录时会发生该错误,这会导致您的应用程序无法找到数据文件。要解决此问题,您需要正确设置工作目录。

如果您使用的是 intelij idea 或 android studio(基于 idea),请检查此链接: Libgdx project Exception in thread "LWJGL Application". Couldn't load file. Error log inside

检查这个,如果你使用的是eclipse: "File not found" when running new LibGDX project

关于java - 大多数基本的 libgdx 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36514876/

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