我查看了以下我认为可行的方法,但它没有。
Android Libgx Frogger 游戏崩溃:找不到类 'com.rengelbert.froggergdx.FroggerGame'
我在所有其他问题之间的主要区别在于,当我创建使用 Gdx-setup.jar 创建的桌面项目时,我没有创建 android 项目。在创建桌面版本后,我决定制作一个 android 项目。
我收到错误消息:
08-23 05:30:09.341: E/dalvikvm(27497): Could not find class 'com.cvgstudios.pokemonchrome.ChromeGame', referenced from method com.cvgstudios.pokemonchrome.RunAndroidChrome.onCreate
08-23 05:30:09.341: W/dalvikvm(27497): VFY: unable to resolve new-instance 1027 (Lcom/cvgstudios/pokemonchrome/ChromeGame;) in Lcom/cvgstudios/pokemonchrome/RunAndroidChrome;
08-23 05:30:09.341: D/dalvikvm(27497): VFY: replacing opcode 0x22 at 0x0014
08-23 05:30:09.341: D/dalvikvm(27497): DexOpt: unable to opt direct call 0x2a07 at 0x16 in Lcom/cvgstudios/pokemonchrome/RunAndroidChrome;.onCreate
08-23 05:30:09.341: D/dalvikvm(27497): Trying to load lib /data/app-lib/com.cvgstudios.pokemonchrome-1/libgdx.so 0x41a79df0
08-23 05:30:09.349: D/dalvikvm(27497): Added shared lib /data/app-lib/com.cvgstudios.pokemonchrome-1/libgdx.so 0x41a79df0
08-23 05:30:09.349: D/dalvikvm(27497): No JNI_OnLoad found in /data/app-lib/com.cvgstudios.pokemonchrome-1/libgdx.so 0x41a79df0, skipping init
08-23 05:30:09.357: D/AndroidRuntime(27497): Shutting down VM
08-23 05:30:09.357: W/dalvikvm(27497): threadid=1: thread exiting with uncaught exception (group=0x41809700)
08-23 05:30:09.364: E/AndroidRuntime(27497): FATAL EXCEPTION: main
08-23 05:30:09.364: E/AndroidRuntime(27497): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cvgstudios.pokemonchrome/com.cvgstudios.pokemonchrome.RunAndroidChrome}: java.lang.NullPointerException
08-23 05:30:09.364: E/AndroidRuntime(27497): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339)
08-23 05:30:09.364: E/AndroidRuntime(27497): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
08-23 05:30:09.364: E/AndroidRuntime(27497): at android.app.ActivityThread.access$600(ActivityThread.java:153)
08-23 05:30:09.364: E/AndroidRuntime(27497): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
08-23 05:30:09.364: E/AndroidRuntime(27497): at android.os.Handler.dispatchMessage(Handler.java:99)
08-23 05:30:09.364: E/AndroidRuntime(27497): at android.os.Looper.loop(Looper.java:137)
08-23 05:30:09.364: E/AndroidRuntime(27497): at android.app.ActivityThread.main(ActivityThread.java:5289)
08-23 05:30:09.364: E/AndroidRuntime(27497): at java.lang.reflect.Method.invokeNative(Native Method)
08-23 05:30:09.364: E/AndroidRuntime(27497): at java.lang.reflect.Method.invoke(Method.java:525)
08-23 05:30:09.364: E/AndroidRuntime(27497): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
08-23 05:30:09.364: E/AndroidRuntime(27497): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
08-23 05:30:09.364: E/AndroidRuntime(27497): at dalvik.system.NativeStart.main(Native Method)
08-23 05:30:09.364: E/AndroidRuntime(27497): Caused by: java.lang.NullPointerException
08-23 05:30:09.364: E/AndroidRuntime(27497): at com.cvgstudios.pokemonchrome.RunAndroidChrome.onCreate(RunAndroidChrome.java:17)
08-23 05:30:09.364: E/AndroidRuntime(27497): at android.app.Activity.performCreate(Activity.java:5133)
08-23 05:30:09.364: E/AndroidRuntime(27497): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-23 05:30:09.364: E/AndroidRuntime(27497): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2293)
08-23 05:30:09.364: E/AndroidRuntime(27497): ... 11 more
如您所见,错误是
找不到从方法 com.cvgstudios.pokemonchrome.RunAndroidChrome.onCreate 引用的类 'com.cvgstudios.pokemonchrome.ChromeGame'
在四处寻找解决我的困境的答案时,一个可能的解决方案是确保它正确导出了主项目。我解决了这个问题:
然而问题仍然存在。
我已经检查了桌面、主和 android 项目的构建路径中的所有订单和导出框。
这是我的课
import android.os.Bundle;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
public class RunAndroidChrome extends AndroidApplication {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
cfg.useGL20 = true;
Gdx.app.log(ChromeGame.LOG,
"Attempting to make Android Chrome Work");
initialize(new com.cvgstudios.pokemonchrome.ChromeGame(), cfg);
}
}