我是 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找到了本教程
最后我找到了解决方案,我不必更改源代码......