0

我是 android 游戏开发的新手,我从 GitHub 下载了 AndEngine 源代码和其他扩展,并创建了一个新项目,从 andengine 的 bin 中添加了 jar,用 SimpleGameActivity 扩展了我的主要活动并覆盖了抽象方法......但是当我尝试要运行这个项目,它说的是致命异常……BLA BLA……我被困在这里了最后 3 小时……不知道该怎么办?

这是我的主要活动代码

import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.util.FPSLogger;

import org.andengine.ui.activity.SimpleBaseGameActivity;


public class MainActivity extends  SimpleBaseGameActivity {

    // ===========================================================
    // Constants
    // ===========================================================

    protected static final int CAMERA_WIDTH = 720;
    protected static final int CAMERA_HEIGHT = 480;

    private Scene mScene;

    @Override
    public EngineOptions onCreateEngineOptions() {
        final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
        return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
    }

    @Override
    public void onCreateResources() {
    }

    @Override
    public Scene onCreateScene() {
        this.mEngine.registerUpdateHandler(new FPSLogger());

        this.mScene = new Scene();
        this.mScene.setBackground(new Background(0, 0, 0));

        return this.mScene;
    }


}

和清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.test"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="15" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-feature android:glEsVersion="0x00020000" android:required="true"/>
    <uses-feature android:name="android.hardware.touchscreen" android:required="false"/>

    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

</manifest>

和日志猫是

12-12 17:26:00.759: W/dalvikvm(20868): Unable to resolve superclass of Lcom/example/test/MainActivity; (558)
12-12 17:26:00.759: W/dalvikvm(20868): Link of class 'Lcom/example/test/MainActivity;' failed
12-12 17:26:00.759: D/AndroidRuntime(20868): Shutting down VM
12-12 17:26:00.759: W/dalvikvm(20868): threadid=1: thread exiting with uncaught exception (group=0x40018578)
12-12 17:26:00.799: E/AndroidRuntime(20868): FATAL EXCEPTION: main
12-12 17:26:00.799: E/AndroidRuntime(20868): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.test/com.example.test.MainActivity}: java.lang.ClassNotFoundException: com.example.test.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.test-1.apk]
12-12 17:26:00.799: E/AndroidRuntime(20868):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
12-12 17:26:00.799: E/AndroidRuntime(20868):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
12-12 17:26:00.799: E/AndroidRuntime(20868):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-12 17:26:00.799: E/AndroidRuntime(20868):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
12-12 17:26:00.799: E/AndroidRuntime(20868):    at android.os.Handler.dispatchMessage(Handler.java:99)
12-12 17:26:00.799: E/AndroidRuntime(20868):    at android.os.Looper.loop(Looper.java:130)
12-12 17:26:00.799: E/AndroidRuntime(20868):    at android.app.ActivityThread.main(ActivityThread.java:3687)
12-12 17:26:00.799: E/AndroidRuntime(20868):    at java.lang.reflect.Method.invokeNative(Native Method)
12-12 17:26:00.799: E/AndroidRuntime(20868):    at java.lang.reflect.Method.invoke(Method.java:507)
12-12 17:26:00.799: E/AndroidRuntime(20868):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
12-12 17:26:00.799: E/AndroidRuntime(20868):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
12-12 17:26:00.799: E/AndroidRuntime(20868):    at dalvik.system.NativeStart.main(Native Method)
12-12 17:26:00.799: E/AndroidRuntime(20868): Caused by: java.lang.ClassNotFoundException: com.example.test.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.test-1.apk]
12-12 17:26:00.799: E/AndroidRuntime(20868):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
12-12 17:26:00.799: E/AndroidRuntime(20868):    at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
12-12 17:26:00.799: E/AndroidRuntime(20868):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
12-12 17:26:00.799: E/AndroidRuntime(20868):    at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
12-12 17:26:00.799: E/AndroidRuntime(20868):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
12-12 17:26:00.799: E/AndroidRuntime(20868):    ... 11 more

我正在尝试在三星 Galaxy pop 中运行它

我在http://www.youtube.com/watch?v=zVIZSKP3tR8找到了本教程

最后我找到了解决方案,我不必更改源代码......

NoClassDefFoundError - Eclipse 和 Android

4

3 回答 3

3

确保 andengine.jar 不仅列在“Java Build Path”>“Libraries”下,而且还导出:“Java Build Path”>“Order and Export”。

或者,如果这不起作用,您可以随时将整个 AndEngine 项目与您的项目联系起来。只需将 AndEngine 项目导入您的 Eclipse(如果您还没有这样做的话),而不是复制 andengine.jar 做:

  • 在 AndEngine 项目中选择“属性”>“ android ”并在“”下标记为“是库
  • 回到你的项目中选择“属性”>“J* ava Build Path *”>“项目”然后“添加->你在你的工作区中看到你所有的项目,选择 AndEngine
  • 切换到“订购和导出”选项卡并确保 AndEngine 也被导出。
  • 选择“属性”>“ android ”并在“”下添加“ AndEngine

这应该可以解决问题(至少它对我有用)如果我弄乱了步骤的顺序,我很抱歉。

于 2012-12-12T14:08:29.167 回答
-1

改成

this.mText = new Text(50, 40, this.mFont, "", 1000, new TextOptions(AutoWrap.LETTERS, AUTOWRAP_WIDTH, HorizontalAlign.CENTER, Text.LEADING_DEFAULT), vertexBufferObjectManager);
于 2013-06-12T05:30:53.790 回答
-1

您的代码可以在我的 Android Studio 上运行,看起来不错,但您必须清理并重建项目。

于 2014-01-26T11:22:17.070 回答