从另一个项目引用时找不到类

时间:2013-08-23 09:45:04

标签: java android eclipse cross-platform libgdx

我已经看过以下哪些我觉得可行,但事实并非如此。

  

Could not find class XXX referenced from method XXX.

     

Hello world, libgdx crashes on phone

     

Android Libgx Frogger game crashing: Could not find class '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.ChromeGame',   从方法中引用   com.cvgstudios.pokemonchrome.RunAndroidChrome.onCreate

在环顾四周找到我的困境的答案时,一个可能的解决方案是确保它正确地导出主项目。我解决了这个问题:

Android Project exporting the main project

然而问题仍然存在。

我已经在桌面,主要和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);
    }
}

1 个答案:

答案 0 :(得分:0)

  

您的班级RunAndroidChrome

中有 导航丢失
import com.cvgstudios.pokemonchrome.ChromeGame;

通常IDE会自动导入依赖的Class。

如果这不是您定义的类,那么您必须忘记添加构建路径 .. 查看here了解如何添加构建路径。

  

另一种可能性是你可能在错误中测试过   机。

同样在cfg.useGL20 = true;我们告诉Android使用OpenGL ES 2.这意味着我们只能在设备上测试它,因为模拟器不支持OpenGL ES 2.如果它有问题,将其切换为false。

检查this链接以获取更多信息