1

我尝试用 libgdx 制作动态壁纸。

在此处输入图像描述

我让一切都喜欢这里

在此处输入图像描述

我的应用程序监听器:

public class GdxTestActivity implements ApplicationListener {

    @Override
    public void create() {
        // TODO Auto-generated method stub

    }
    @Override
    public void dispose() {
        // TODO Auto-generated method stub

    }
    @Override
    public void pause() {
        // TODO Auto-generated method stub

    }
    @Override
    public void render() {
        // TODO Auto-generated method stub

    }
    @Override
    public void resize(int arg0, int arg1) {
        // TODO Auto-generated method stub

    }
    @Override
    public void resume() {
        // TODO Auto-generated method stub

    }
}

动态壁纸.java:

public class LiveWallpaper extends AndroidLiveWallpaperService 
{
    @Override
    public ApplicationListener createListener (boolean isPreview) {
            return new GdxTestActivity();
    }

    @Override
    public AndroidApplicationConfiguration createConfig () {
            return new AndroidApplicationConfiguration();
    }

    @Override
    public void offsetChange (ApplicationListener listener, float xOffset, float yOffset, float xOffsetStep, float yOffsetStep,
            int xPixelOffset, int yPixelOffset) {
            Gdx.app.log("LiveWallpaper", "offset changed: " + xOffset + ", " + yOffset);
    }

为什么我在加载应用程序时看到此错误?

Link of class 'Lcom/example/gdxtest01/GdxTestActivity;' failed
Could not find class 'com.example.gdxtest01.GdxTestActivity', referenced from method com.example.gdxtest01.LiveWallpaper.createListener
VFY: unable to resolve new-instance 620 (Lcom/example/gdxtest01/GdxTestActivity;) in Lcom/example/gdxtest01/LiveWallpaper;
VFY: unable to find class referenced in signature (Lcom/badlogic/gdx/ApplicationListener;)
VFY: unable to resolve static field 726 (app) in Lcom/badlogic/gdx/Gdx;
Link of class 'Lcom/badlogic/gdx/backends/android/AndroidLiveWallpaper;' failed
Could not find class 'com.badlogic.gdx.backends.android.AndroidLiveWallpaper', referenced from method com.badlogic.gdx.backends.android.AndroidLiveWallpaperService$AndroidWallpaperEngine.onCreate
VFY: unable to resolve new-instance 520 (Lcom/badlogic/gdx/backends/android/AndroidLiveWallpaper;) in Lcom/badlogic/gdx/backends/android/AndroidLiveWallpaperService$AndroidWallpaperEngine;
VFY: unable to resolve interface method 3145: Lcom/badlogic/gdx/ApplicationListener;.dispose ()V
Link of class 'Lcom/badlogic/gdx/backends/android/AndroidLiveWallpaper;' failed
...
Link of class 'Lcom/badlogic/gdx/backends/android/AndroidLiveWallpaper;' failed
VFY: unable to resolve instance field 1010
02-11 21:31:51.398: threadid=1: thread exiting with uncaught exception (group=0x4001d560)
FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.badlogic.gdx.backends.android.AndroidLiveWallpaper
at com.badlogic.gdx.backends.android.AndroidLiveWallpaperService$AndroidWallpaperEngine.onCreate(AndroidLiveWallpaperService.java:108)
at android.service.wallpaper.WallpaperService$Engine.attach(WallpaperService.java:648)
at android.service.wallpaper.WallpaperService$IWallpaperEngineWrapper.executeMessage(WallpaperService.java:875)
at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:61)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)

在一些魔法之后一切都很好。

4

1 回答 1

0

来自gdx.jar主项目的 未包含在 Android 中.apk。(所有的com.badlogic.gdx.*类都在这个 jar 文件中。)

请参阅手动项目设置中的步骤 4、5 和 6:http ://code.google.com/p/libgdx/wiki/ProjectSetup#Android_project_setup

您可能只是缺少将“gdx.jar”标记为“已导出”的位。右键单击项目,选择Build Path -> Configure Build Path .... 选择Order and Export选项卡,确保“gdx.jar”旁边有一个复选标记。

于 2013-02-11T18:01:33.613 回答