问题
I just started Android Game Development and I ran into a stupid problem. I want to run an application on my phone or virtual machine and I'm getting this error:
01-11 21:16:45.362: E/AndroidRuntime(19063): FATAL EXCEPTION: main
01-11 21:16:45.362: E/AndroidRuntime(19063): Process: com.mygdx.game, PID: 19063
01-11 21:16:45.362: E/AndroidRuntime(19063): 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/arm, /vendor/lib, /system/lib]]
01-11 21:16:45.362: E/AndroidRuntime(19063): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2515)
01-11 21:16:45.362: E/AndroidRuntime(19063): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723)
01-11 21:16:45.362: E/AndroidRuntime(19063): at android.app.ActivityThread.access$900(ActivityThread.java:172)
01-11 21:16:45.362: E/AndroidRuntime(19063): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422)
01-11 21:16:45.362: E/AndroidRuntime(19063): at android.os.Handler.dispatchMessage(Handler.java:102)
01-11 21:16:45.362: E/AndroidRuntime(19063): at android.os.Looper.loop(Looper.java:145)
01-11 21:16:45.362: E/AndroidRuntime(19063): at android.app.ActivityThread.main(ActivityThread.java:5832)
01-11 21:16:45.362: E/AndroidRuntime(19063): at java.lang.reflect.Method.invoke(Native Method)
01-11 21:16:45.362: E/AndroidRuntime(19063): at java.lang.reflect.Method.invoke(Method.java:372)
01-11 21:16:45.362: E/AndroidRuntime(19063): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
01-11 21:16:45.362: E/AndroidRuntime(19063): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
01-11 21:16:45.362: E/AndroidRuntime(19063): 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/arm, /vendor/lib, /system/lib]]
01-11 21:16:45.362: E/AndroidRuntime(19063): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
01-11 21:16:45.362: E/AndroidRuntime(19063): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
01-11 21:16:45.362: E/AndroidRuntime(19063): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
01-11 21:16:45.362: E/AndroidRuntime(19063): at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
01-11 21:16:45.362: E/AndroidRuntime(19063): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2505)
01-11 21:16:45.362: E/AndroidRuntime(19063): ... 10 more
01-11 21:16:45.362: E/AndroidRuntime(19063): Suppressed: java.lang.NoClassDefFoundError: com.mygdx.game.AndroidLauncher
01-11 21:16:45.362: E/AndroidRuntime(19063): at dalvik.system.DexFile.defineClassNative(Native Method)
01-11 21:16:45.362: E/AndroidRuntime(19063): at dalvik.system.DexFile.defineClass(DexFile.java:226)
01-11 21:16:45.362: E/AndroidRuntime(19063): at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
01-11 21:16:45.362: E/AndroidRuntime(19063): at dalvik.system.DexPathList.findClass(DexPathList.java:321)
01-11 21:16:45.362: E/AndroidRuntime(19063): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
01-11 21:16:45.362: E/AndroidRuntime(19063): ... 14 more
01-11 21:16:45.362: E/AndroidRuntime(19063): Suppressed: java.lang.ClassNotFoundException: com.mygdx.game.AndroidLauncher
01-11 21:16:45.362: E/AndroidRuntime(19063): at java.lang.Class.classForName(Native Method)
01-11 21:16:45.362: E/AndroidRuntime(19063): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
01-11 21:16:45.362: E/AndroidRuntime(19063): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
01-11 21:16:45.362: E/AndroidRuntime(19063): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
01-11 21:16:45.362: E/AndroidRuntime(19063): ... 13 more
01-11 21:16:45.362: E/AndroidRuntime(19063): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
If you have experienced it, please help me. Have a nice day.
回答1:
Right click on the android project and click properties -> Java Build Path -> Order and Export, and tick all the boxes.
Clean the project and rebuild.
The error comes when switching from different android API's in eclipse.
Also usually this happens on a new libGDX project when you don't have the default Android SDK (mine was 19 which I don't have), which is fixed by Project -> properties -> Android, and select the build target.
Always clean the project after making these changes.
The above two issues are ones I am always coming across with libGDX and Eclipse, either when importing a project, just setting a new one up or when I'm reinstalling Android SDK's.
Hope this helps. ;-)
来源:https://stackoverflow.com/questions/34729753/libgdx-android-in-eclipse-unable-to-instantiate-activity-componentinfo