我寫了下面的代碼,現在「格拉默」按鈕,程序停止。 這是我的‘主要活動’。的Android程序啓動程序並點擊時無法啓動
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button grammerButton = (Button)findViewById(R.id.grammar);
grammerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, Grammer.class);
startActivity(intent);
}
});
}
}
的logcat的分中startActivity(intent);
錯誤我很無奈試圖找出錯誤。
我張貼的logcat的錯誤
02-26 23:33:26.991: D/AndroidRuntime(4604): Shutting down VM
02-26 23:33:26.991: W/dalvikvm(4604): threadid=1: thread exiting with uncaught exception (group=0x40015560)
02-26 23:33:27.011: E/AndroidRuntime(4604): FATAL EXCEPTION: main
02-26 23:33:27.011: E/AndroidRuntime(4604): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.grammer/com.example.grammer.Grammer}; have you declared this activity in your AndroidManifest.xml?
02-26 23:33:27.011: E/AndroidRuntime(4604): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
02-26 23:33:27.011: E/AndroidRuntime(4604): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
02-26 23:33:27.011: E/AndroidRuntime(4604): at android.app.Activity.startActivityForResult(Activity.java:2827)
02-26 23:33:27.011: E/AndroidRuntime(4604): at android.app.Activity.startActivity(Activity.java:2933)
02-26 23:33:27.011: E/AndroidRuntime(4604): at com.example.grammer.MainActivity$1.onClick(MainActivity.java:31)
02-26 23:33:27.011: E/AndroidRuntime(4604): at android.view.View.performClick(View.java:2485)
02-26 23:33:27.011: E/AndroidRuntime(4604): at android.view.View$PerformClick.run(View.java:9080)
02-26 23:33:27.011: E/AndroidRuntime(4604): at android.os.Handler.handleCallback(Handler.java:587)
02-26 23:33:27.011: E/AndroidRuntime(4604): at android.os.Handler.dispatchMessage(Handler.java:92)
02-26 23:33:27.011: E/AndroidRuntime(4604): at android.os.Looper.loop(Looper.java:123)
02-26 23:33:27.011: E/AndroidRuntime(4604): at android.app.ActivityThread.main(ActivityThread.java:3683)
02-26 23:33:27.011: E/AndroidRuntime(4604): at java.lang.reflect.Method.invokeNative(Native Method)
02-26 23:33:27.011: E/AndroidRuntime(4604): at java.lang.reflect.Method.invoke(Method.java:507)
02-26 23:33:27.011: E/AndroidRuntime(4604): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-26 23:33:27.011: E/AndroidRuntime(4604): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-26 23:33:27.011: E/AndroidRuntime(4604): at dalvik.system.NativeStart.main(Native Method)
這是我的manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.grammer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.grammer.MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.grammer.grammar.Grammer"
android:label="@string/title_activity_grammer" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.grammer.MainActivity" />
</activity>
<activity
android:name="com.example.grammer.grammar.GrammarRegularActivityActivity"
android:label="@string/title_activity_grammar_regular" >
</activity>
<activity
android:name="com.example.grammer.grammar.Grammer_regular_page2er_regular_page2"
android:label="@string/title_activity_grammer_regular_page2" >
</activity>
<activity
android:name="com.example.grammer.grammar.Exerciseexample.grammer.Exercise"
android:label="@string/title_activity_exercise" >
</activity>
<activity
android:name="com.example.grammer.grammar.Amisare2Amisare2"
android:label="@string/title_activity_amisare2" >
</activity>
</application>
</manifest>
請發佈錯誤的logcat輸出。 – jademcosta
此外,發佈AndroidManifest.xml –
這只是日誌中的許多行中的一行,並沒有顯示錯誤。發佈更多的日誌。 – Pedantic