2014-04-28 33 views
0

我用菜單畫面和啓動畫面進行了遊戲。我遵循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> 

+0

有在logcat中的任何錯誤? – SilentKiller

+0

從logcat發佈堆棧跟蹤。 – Karakuri

+0

'' – Blackbelt

回答

0

試試這個..

更改這個..

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

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

我沒想到有人這麼快回復我!非常感謝你!有用! – user3580731

+0

@ user3580731很高興幫助。快樂編碼。 Ple接受我的答覆。 – Hariharan