Splash to Menu崩溃

时间:2014-04-24 03:58:55

标签: android andengine

当启动画面移动到菜单时,程序崩溃了。 崩溃时的logcat详细信息如下:

04-24 11:40:17.082: E/AndroidRuntime(3180):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508)
04-24 11:40:17.082: E/AndroidRuntime(3180):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
04-24 11:40:17.082: E/AndroidRuntime(3180):     at android.app.Activity.startActivityForResult(Activity.java:3190)
04-24 11:40:17.082: E/AndroidRuntime(3180):     at android.app.Activity.startActivity(Activity.java:3297)
04-24 11:40:17.082: E/AndroidRuntime(3180):     at com.pearson.lagp.v3.StartActivity$1.run(StartActivity.java:68)
04-24 11:40:17.082: E/AndroidRuntime(3180):     at android.os.Handler.handleCallback(Handler.java:605)
04-24 11:40:17.082: E/AndroidRuntime(3180):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-24 11:40:17.082: E/AndroidRuntime(3180):     at android.os.Looper.loop(Looper.java:137)
04-24 11:40:17.082: E/AndroidRuntime(3180):     at android.app.ActivityThread.main(ActivityThread.java:4448)
04-24 11:40:17.082: E/AndroidRuntime(3180):     at java.lang.reflect.Method.invokeNative(Native Method)
04-24 11:40:17.082: E/AndroidRuntime(3180):     at java.lang.reflect.Method.invoke(Method.java:511)
04-24 11:40:17.082: E/AndroidRuntime(3180):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
04-24 11:40:17.082: E/AndroidRuntime(3180):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
04-24 11:40:17.082: E/AndroidRuntime(3180):     at dalvik.system.NativeStart.main(Native Method)

这是关于屏幕移动的程序:

package com.pearson.lagp.v3;
import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.util.FPSLogger;
import org.anddev.andengine.opengl.font.Font;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;

import android.content.Intent;
import android.os.Handler;
public class StartActivity extends BaseGameActivity {
    private static final int CAMERA_WIDTH = 480;
    private static final int CAMERA_HEIGHT = 320;
    private Camera mCamera;
    private BitmapTextureAtlas mBitmapTextureAtlas;
    private TextureRegion mSplashTextureRegion;
    private Font mFont;
    private Handler mHandler;

    public Engine onLoadEngine() {
        mHandler=new Handler();
        mHandler.removeCallbacks(mLaunchTask);
        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() {
        mBitmapTextureAtlas = new BitmapTextureAtlas(512, 512,TextureOptions.BILINEAR_PREMULTIPLYALPHA);
        mSplashTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            this.mBitmapTextureAtlas, this, "Splashscreen.png", 0, 0
        );
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
    }
    @Override
    public Scene onLoadScene() {
        this.mEngine.registerUpdateHandler(new FPSLogger());
        final Scene scene = new Scene(1);
        /* Center the splash on the camera. */
        final int centerX =(CAMERA_WIDTH - this.mSplashTextureRegion.getWidth()) / 2;
        final int centerY =(CAMERA_HEIGHT -this.mSplashTextureRegion.getHeight()) / 2;
        /* Create the sprite and add it to the scene. */
        final Sprite splash = new Sprite(centerX,centerY, this.mSplashTextureRegion);
        scene.getLastChild().attachChild(splash);
        return scene;
    }
    @Override
    public void onLoadComplete() {
        mHandler.postDelayed(mLaunchTask, 3000);
    }

    private Runnable mLaunchTask=new Runnable(){
        public void run(){

            Intent mIntent=new Intent(StartActivity.this, MainMenuActivity.class);
            StartActivity.this.startActivity(mIntent);
        }
    };
}

修改后这是我的清单:

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.pearson.lagp.v3.StartActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity 
            android:name="com.pearson.lagp.v3.MainMenuActivity"
            android:label="@string/menu_name">
        </activity>
    </application>

</manifest>

为什么它崩溃了?

2 个答案:

答案 0 :(得分:0)

您是否在清单中声明了您的活动?

使用正确的包名检查您在清单上的活动?

Android OnClick error

Unable to find explicit activity class and unable to instantiate activity

答案 1 :(得分:0)

试试这个..你的活动应该在清单

中像这样被涂抹
    android:name="com.example.namespace.Firstactivity"
清单中的

(或)意图过滤器声明在错误的位置。重命名您的活动名称并发布您的清单。

相关问题