AndEngine:示例不起作用

时间:2012-05-09 15:26:01

标签: android andengine

我刚从AndEngine主页复制了一个示例,但应用程序总是被迫在模拟器中停止:((请帮助我。 这是主要的活动:

    public class HelloMe extends BaseGameActivity {

   private static final int CAMERA_WIDTH = 720;

   private static final int CAMERA_HEIGHT = 480;

  // ===========================================================
  // Fields
  // ===========================================================

   private Camera mCamera;
   private BitmapTextureAtlas mFontTexture;
   private Font mFont;

@Override
public Engine onLoadEngine() {
    // TODO Auto-generated method stub
    this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
       return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera));

}

@Override
public void onLoadResources() {
    // TODO Auto-generated method stub
    this.mFontTexture = new BitmapTextureAtlas(256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);

    this.mFont = new Font(this.mFontTexture, Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 32, true, Color.BLACK);

    this.mEngine.getTextureManager().loadTexture(this.mFontTexture);
    this.getFontManager().loadFont(this.mFont);

}

@Override
public Scene onLoadScene() {

    this.mEngine.registerUpdateHandler(new FPSLogger());

    final Scene scene = new Scene();
    scene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));

    final Text textCenter = new Text(100, 60, this.mFont, "Hello AndEngine!\nYou can even   have multilined text!", HorizontalAlign.CENTER);
    final Text textLeft = new Text(100, 200, this.mFont, "Also left aligned!\nLorem ipsum dolor sit amat...", HorizontalAlign.LEFT);
    final Text textRight = new Text(100, 340, this.mFont, "And right aligned!\nLorem ipsum dolor sit amat...", HorizontalAlign.RIGHT);

    scene.attachChild(textCenter);
    scene.attachChild(textLeft);
    scene.attachChild(textRight);

    return scene;
}

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

}

}

清单文件:

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

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

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".HelloMe"
        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>

</manifest>

我使用的是Android 4.0.3,并且andengine.jar已添加到Build Path中。 AndEngine可以只运行Android 2.2吗?提前感谢:D。

PS:这是堆栈跟踪:

        05-09 22:04:08.311: E/AndroidRuntime(628): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.hello/com.hello.HelloMe}: java.lang.ClassNotFoundException: com.hello.HelloMe
        05-09 22:04:08.311: E/AndroidRuntime(628):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
        05-09 22:04:08.311: E/AndroidRuntime(628):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
        05-09 22:04:08.311: E/AndroidRuntime(628):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
        05-09 22:04:08.311: E/AndroidRuntime(628):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
        05-09 22:04:08.311: E/AndroidRuntime(628):  at android.os.Handler.dispatchMessage(Handler.java:99)
        05-09 22:04:08.311: E/AndroidRuntime(628):  at android.os.Looper.loop(Looper.java:137)
        05-09 22:04:08.311: E/AndroidRuntime(628):  at android.app.ActivityThread.main(ActivityThread.java:4424)
        05-09 22:04:08.311: E/AndroidRuntime(628):  at java.lang.reflect.Method.invokeNative(Native Method)
        05-09 22:04:08.311: E/AndroidRuntime(628):  at java.lang.reflect.Method.invoke(Method.java:511)
        05-09 22:04:08.311: E/AndroidRuntime(628):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
        05-09 22:04:08.311: E/AndroidRuntime(628):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
        05-09 22:04:08.311: E/AndroidRuntime(628):  at dalvik.system.NativeStart.main(Native Method)
        05-09 22:04:08.311: E/AndroidRuntime(628): Caused by: java.lang.ClassNotFoundException: com.hello.HelloMe
        05-09 22:04:08.311: E/AndroidRuntime(628):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
        05-09 22:04:08.311: E/AndroidRuntime(628):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
        05-09 22:04:08.311: E/AndroidRuntime(628):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
        05-09 22:04:08.311: E/AndroidRuntime(628):  at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
        05-09 22:04:08.311: E/AndroidRuntime(628):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)

2 个答案:

答案 0 :(得分:2)

AndEngine,你使用的版本看起来不像最新版本,不支持模拟器。尝试插入手机并运行它,它可能会工作。

答案 1 :(得分:0)

添加“libs”文件夹并复制andengine.jar并编译。