完成libGDX android 库的本教程后,桌面项目运行良好,并且 eclipse 指出的任何地方都没有错误。当我在我的 Nexus 7 上运行它时,(运行 Android 4.3)白屏闪烁(可能是应用程序的默认背景),然后它返回主屏幕并显示“不幸的是 my-first-triangle-android 有停了。”
这是我从 LogCat 得到的错误:
08-02 20:11:52.940: E/AndroidRuntime(4095): FATAL EXCEPTION: main
08-02 20:11:52.940: E/AndroidRuntime(4095): java.lang.NoClassDefFoundError: com.test.myfirsttriangle.MyFirstTriangle
08-02 20:11:52.940: E/AndroidRuntime(4095): at com.example.my_first_triangle_android.MainActivity.onCreate(MainActivity.java:12)
08-02 20:11:52.940: E/AndroidRuntime(4095): at android.app.Activity.performCreate(Activity.java:5133)
08-02 20:11:52.940: E/AndroidRuntime(4095): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-02 20:11:52.940: E/AndroidRuntime(4095): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-02 20:11:52.940: E/AndroidRuntime(4095): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-02 20:11:52.940: E/AndroidRuntime(4095): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-02 20:11:52.940: E/AndroidRuntime(4095): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-02 20:11:52.940: E/AndroidRuntime(4095): at android.os.Handler.dispatchMessage(Handler.java:99)
08-02 20:11:52.940: E/AndroidRuntime(4095): at android.os.Looper.loop(Looper.java:137)
08-02 20:11:52.940: E/AndroidRuntime(4095): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-02 20:11:52.940: E/AndroidRuntime(4095): at java.lang.reflect.Method.invokeNative(Native Method)
08-02 20:11:52.940: E/AndroidRuntime(4095): at java.lang.reflect.Method.invoke(Method.java:525)
08-02 20:11:52.940: E/AndroidRuntime(4095): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-02 20:11:52.940: E/AndroidRuntime(4095): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-02 20:11:52.940: E/AndroidRuntime(4095): at dalvik.system.NativeStart.main(Native Method)
项目:我的第一个三角形
MyFirstTriangle.java:
package com.test.myfirsttriangle;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
public class MyFirstTriangle implements ApplicationListener {
private Mesh mesh;
@Override
public void create() {
if (mesh == null) {
mesh = new Mesh(true, 3, 3,
new VertexAttribute(Usage.Position, 3, "a_position"));
mesh.setVertices(new float[] { -0.5f, -0.5f, 0,
0.5f, -0.5f, 0,
0, 0.5f, 0 });
mesh.setIndices(new short[] { 0, 1, 2 });
}
}
@Override
public void dispose() { }
@Override
public void pause() { }
@Override
public void render() {
mesh.render(GL10.GL_TRIANGLES, 0, 3);
}
@Override
public void resize(int width, int height) { }
@Override
public void resume() { }
}
MyFirstTriangleDesktop.java
package com.test.myfirsttriangle;
import com.badlogic.gdx.backends.jogl.JoglApplication;
public class MyFirstTriangleDesktop {
public static void main (String[] argv) {
new JoglApplication(new MyFirstTriangle(), "My First Triangle", 480, 320, false);
}
}
项目:我的第一个三角形机器人
MainActivity.java:
package com.example.my_first_triangle_android;
import android.os.Bundle;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.test.myfirsttriangle.MyFirstTriangle;
public class MainActivity extends AndroidApplication {
@Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initialize(new MyFirstTriangle(), false);
}
}
额外信息:我正在运行这个 Eclipse:http: //developer.android.com/sdk/installing/bundle.html
编辑
似乎来自 log cat 的错误
08-02 20:11:52.940: E/AndroidRuntime(4095): FATAL EXCEPTION: main
08-02 20:11:52.940: E/AndroidRuntime(4095): java.lang.NoClassDefFoundError: com.test.myfirsttriangle.MyFirstTriangle
08-02 20:11:52.940: E/AndroidRuntime(4095): at com.example.my_first_triangle_android.MainActivity.onCreate(MainActivity.java:12)
这条线有问题:
initialize(new MyFirstTriangle(), false);