我很努力從我的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;
}
}
它在logcat中給出了什麼錯誤? – Stephen
它沒有給出任何據我所知 –
你說,當你點擊按鈕,應用程序只是崩潰,所以它怎麼不會給你任何錯誤? –