我想在布局上使用一个按钮将用户切换到新活动。当我按下按钮时,它会抛出一个致命的错误。
首先 - 这是我的.java中的按钮:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button viewAbout = (Button) findViewById(R.id.buttonAbout);
// //onClickListeners// //
viewAbout.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, About.class);
startActivity(i); //This is line 50
//This is line 51 where the logcat will refer
} // This is line 52
});
}
}
这是我收到的LogCat:
02-22 12:44:22.095: E/AndroidRuntime(2743): FATAL EXCEPTION: main
02-22 12:44:22.095: E/AndroidRuntime(2743): Process: biz.midl.debteliminator, PID: 2743
02-22 12:44:22.095: E/AndroidRuntime(2743): android.content.ActivityNotFoundException: Unable to find explicit activity class {biz.midl.debteliminator/biz.midl.debteliminator.About}; have you declared this activity in your AndroidManifest.xml?
02-22 12:44:22.095: E/AndroidRuntime(2743): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
02-22 12:44:22.095: E/AndroidRuntime(2743): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
02-22 12:44:22.095: E/AndroidRuntime(2743): at android.app.Activity.startActivityForResult(Activity.java:3424)
02-22 12:44:22.095: E/AndroidRuntime(2743): at android.app.Activity.startActivityForResult(Activity.java:3385)
02-22 12:44:22.095: E/AndroidRuntime(2743): at android.app.Activity.startActivity(Activity.java:3627)
02-22 12:44:22.095: E/AndroidRuntime(2743): at android.app.Activity.startActivity(Activity.java:3595)
02-22 12:44:22.095: E/AndroidRuntime(2743): at biz.midl.debteliminator.MainActivity$1.onClick(MainActivity.java:51)
02-22 12:44:22.095: E/AndroidRuntime(2743): at android.view.View.performClick(View.java:4438)
02-22 12:44:22.095: E/AndroidRuntime(2743): at android.view.View$PerformClick.run(View.java:18422)
02-22 12:44:22.095: E/AndroidRuntime(2743): at android.os.Handler.handleCallback(Handler.java:733)
02-22 12:44:22.095: E/AndroidRuntime(2743): at android.os.Handler.dispatchMessage(Handler.java:95)
02-22 12:44:22.095: E/AndroidRuntime(2743): at android.os.Looper.loop(Looper.java:136)
02-22 12:44:22.095: E/AndroidRuntime(2743): at android.app.ActivityThread.main(ActivityThread.java:5017)
02-22 12:44:22.095: E/AndroidRuntime(2743): at java.lang.reflect.Method.invokeNative(Native Method)
02-22 12:44:22.095: E/AndroidRuntime(2743): at java.lang.reflect.Method.invoke(Method.java:515)
02-22 12:44:22.095: E/AndroidRuntime(2743): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-22 12:44:22.095: E/AndroidRuntime(2743): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-22 12:44:22.095: E/AndroidRuntime(2743): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
在输入时我意识到我的Manifest.xml没有更新:使用我的About.java的以下声明
<activity
android:name="biz.midl.debteliminator.About"
android:label="@string/app_name"
android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.ABOUT" />
</intent-filter>
</activity>
通过此更新 - 该应用程序现在可以正常运行。