LibGDX'MyFirstTriangle'示例在启动时崩溃 [英] LibGDX 'MyFirstTriangle' example crashes on startup

查看:81
本文介绍了LibGDX'MyFirstTriangle'示例在启动时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

针对libGDX android库,在完成本教程后,将运行桌面项目很好,月食指出的任何地方都没有错误.当我在Nexus 7(运行Android 4.3)上运行它时,白屏闪烁(可能是应用程序的默认背景),然后返回主屏幕,并说:不幸的是,我的第一个三角机器人遇到了停止了."

Upon finishing this tutorial for the libGDX android library, the desktop project runs fine and there are no errors anywhere that eclipse points out. When I go to run it on my Nexus 7, (running Android 4.3) the white screen flashes (presumably the default background of the app) and then it goes back to the home screen and says "Unfortunately my-first-triangle-android has stopped."

这是我从LogCat得到的错误:

This is the error I get from 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)

项目:我的第一个三角形

Project: my-first-triangle

MyFirstTriangle.java:

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

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);       
    }
}

项目:my-first-triangle-android

Project: my-first-triangle-android

MainActivity.java:

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);               
        }
}

其他信息: 我正在运行这个月食: http://developer.android.com/sdk/installing/bundle.html

Extra info: I am running this eclipse: http://developer.android.com/sdk/installing/bundle.html

好像是日志猫的错误

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);               

推荐答案

从多个项目中构建Android应用要比应做的要复杂得多.基本上,当ADT构建您的Android程序包时,它忘记在构建中包括Libgdx核心"程序包(my-first-triangle).

Building Android apps out of multiple projects is far more fiddly than it should be. Basically, when the ADT built your Android package it forgot to include your Libgdx "core" package (my-first-triangle) in the build.

在Package Explorer中右键单击您的Android项目,单击Properties,选择Java Build Path.该问题最有可能在Order and Export选项卡上.确保您的my-first-triangle项目已标记为要导出(应设置对勾标记).

Right-click on your Android Project in the Package Explorer, click Properties, select the Java Build Path. The problem is most likely on the Order and Export tab. Make sure your my-first-triangle project is marked for export (it should have a checkmark set).

这不是Libgdx问题.只是Libgdx将应用程序分解为多个程序包,因此比普通的Android用户更容易被该程序绊倒.

This isn't a Libgdx issue. Its just that Libgdx breaks applications into multiple packages so gets tripped up by this more often than regular Android users.

这篇关于LibGDX'MyFirstTriangle'示例在启动时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆