-1

我很努力從我的android應用程序中的選項菜單獲取活動。聲明Android清單中的多個活動

相關選項用於幫助頁面。我用這個(開關的情況下)的代碼如下,並幫助選項是在底部:

@Override 
// Respond to item selected on OPTIONS MENU 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle item selection 
    switch (item.getItemId()) { 
    //put data in Intent 
     case R.id.settings: 
      Toast.makeText(this, "Settings chosen", Toast.LENGTH_SHORT).show(); 
      return true; 
    case R.id.easy: 
     Toast.makeText(this, "Easy chosen", Toast.LENGTH_SHORT).show(); 
     return true; 
    case R.id.medium: 
     Toast.makeText(this, "Medium chosen", Toast.LENGTH_SHORT).show(); 
     return true; 
    case R.id.hard: 
     Toast.makeText(this, "Hard chosen", Toast.LENGTH_SHORT).show(); 
     return true; 
    case R.id.scores: 
     Toast.makeText(this, "High Scores chosen", Toast.LENGTH_SHORT).show(); 
     return true; 
    case R.id.help: 
     Intent intent = new Intent(this, HelpActivity.class); 
     startActivity(intent); 
     return true; 
    default: 
     return super.onOptionsItemSelected(item); 
    } 
} 

我想我有它正確地設置在清單中,但是當我點擊幫助選項,應用程序只是崩潰。我明顯低於:

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

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

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name="cct.mad.lab.MainMenu" 
     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=".GameActivity" 
     android:label="@string/app_name" > 
    </activity> 
    <activity 
     android:name=".HelpActivity" 
     android:label="@string/app_name" > 
    </activity> 

我要去假設我做錯了什麼是顯而易見的給別人,但我看不出它現在。

感謝所有幫助

編輯:我將我的HelpActivity類,因爲我認爲這可能是東西是不對的在那裏。我是一個相對的新手在此:

public class HelpActivity extends Activity { 

public void init() { 

    Intent helpScreen = new Intent(HelpActivity.this, MainMenu.class); 

    startActivity(helpScreen); 

} 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.help_page); 
    init(); 
} 

InputStream iFile = getResources().openRawResource(R.raw.gamehelp); 

private String inputStreamToString(InputStream iFile) { 
    TextView helpText = (TextView) findViewById(R.id.tvHelpText); 
    String strFile = inputStreamToString(iFile); 
    helpText.setText(strFile); 
    return strFile; 
} 
} 
+0

它在logcat中給出了什麼錯誤? – Stephen

+0

它沒有給出任何據我所知 –

+0

你說,當你點擊按鈕,應用程序只是崩潰,所以它怎麼不會給你任何錯誤? –

回答

0

我認爲這個問題可能會在這裏:

Intent helpScreen = new Intent(HelpActivity.this, MainMenu.class); 
startActivity(helpScreen); 

嘗試註釋掉該行的onCreate方法

init(); 

看來,你試圖開始另一個活動,只要你開始幫助活動

+0

嗯,不工作。我需要在某個地方的HelpActivity類中使用'setOnClickListener'嗎? –

+0

我有一個預感,只是覺得我會嘗試並註釋掉InputStream iFile'bit,它現在可以工作,所以問題就在那裏。不知道有什麼問題,但我會再看看。對不起,浪費你的時間 –

0

我的問題是與嘗試將原始資源文件(.txt)添加到佈局。當我評論這一點時,它開放的活動很好。所以,這是另一個問題。

相關問題