我是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>
和Log Cat
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最后我得到了解决方案,我不必更改源代码......
答案 0 :(得分:3)
确保andengine.jar不仅列在“Java Build Path”&gt;下面。 “库”但导出:“Java构建路径”&gt; “订单和出口”。
或如果不能解决问题,您可以随时将整个AndEngine项目与您的项目链接起来。只需将AndEngine项目导入Eclipse(如果还没有完成),而不是复制andengine.jar:
这应该可以解决问题(至少它对我有用)我很抱歉,如果我可能搞砸了步骤的顺序。
答案 1 :(得分:-1)
更改为
this.mText = new Text(50, 40, this.mFont, "", 1000, new TextOptions(AutoWrap.LETTERS, AUTOWRAP_WIDTH, HorizontalAlign.CENTER, Text.LEADING_DEFAULT), vertexBufferObjectManager);
答案 2 :(得分:-1)
您的代码在我的Android Studio上运行,看起来很不错,但您必须清理并重建项目。