启动画面后应用程序崩溃(当菜单屏幕出现时)

时间:2014-04-28 09:51:54

标签: java android eclipse

我用菜单屏幕和启动画面制作了游戏。我按照YouTube教程中的步骤进行操作。在闪屏结束后(当菜单屏幕应该出现时),应用程序每次都会崩溃。

这是我的代码,没有错误。问题出在哪里?

启动画面:

package com.group5.littlered;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;


public class MyMain extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    //Remove title bar
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    //Remove notification bar
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

   //set content view AFTER ABOVE sequence (to avoid crash)
    this.setContentView(R.layout.main|R.layout.splash); 
    setContentView(R.layout.splash);
    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(5000);
            } catch (InterruptedException e){
                e.printStackTrace();
            }finally{
                Intent openStartingPoint = new Intent("com.group5.littlered.STARTINGPOINT");
                startActivity(openStartingPoint);               
                }   
        }
    };
    timer.start();
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    finish();
  }
}

菜单屏幕:

package com.group5.littlered;

import android.app.Activity;
import android.os.Bundle;

public class MyMenu extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}}

andriodManifest.xml

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

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MyMain"
        android:label="@string/app_name"
        android:screenOrientation="landscape"
        android:configChanges="keyboard|keyboardHidden|orientation" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MyMenu"
        android:label="@string/app_name"
        android:screenOrientation="landscape"
        android:configChanges="keyboard|keyboardHidden|orientation" >
        <intent-filter>
            <action android:name="com.group5.littlered.SPLASH" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

</application>

1 个答案:

答案 0 :(得分:0)

试试这个..

改变这个..

Intent openStartingPoint = new Intent("com.group5.littlered.STARTINGPOINT");
startActivity(openStartingPoint);    

Intent openStartingPoint = new Intent(MyMain.this,MyMenu.class);
startActivity(openStartingPoint);