如何创建新活动?
我已经尝试过这段代码,但是当我启动它时我的应用程序崩溃了......
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.newfolder:
startActivity(new Intent(this, Newfolder.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
LogCat 错误:
02-04 18:48:07.987: E/AndroidRuntime(839): FATAL EXCEPTION: main
02-04 18:48:07.987: E/AndroidRuntime(839): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.androidexplorer/com.example.androidexplorer.Newfolder}; have you declared this activity in your AndroidManifest.xml?
02-04 18:48:07.987: E/AndroidRuntime(839): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508)
02-04 18:48:07.987: E/AndroidRuntime(839): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
02-04 18:48:07.987: E/AndroidRuntime(839): at android.app.Activity.startActivityForResult(Activity.java:3190)
02-04 18:48:07.987: E/AndroidRuntime(839): at android.app.Activity.startActivity(Activity.java:3297)
02-04 18:48:07.987: E/AndroidRuntime(839): at com.example.androidexplorer.MainActivity.onMenuItemSelected(MainActivity.java:105)
02-04 18:48:07.987: E/AndroidRuntime(839): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:950)
02-04 18:48:07.987: E/AndroidRuntime(839): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
02-04 18:48:07.987: E/AndroidRuntime(839): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
02-04 18:48:07.987: E/AndroidRuntime(839): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
02-04 18:48:07.987: E/AndroidRuntime(839): at com.android.internal.view.menu.ListMenuPresenter.onItemClick(ListMenuPresenter.java:163)
02-04 18:48:07.987: E/AndroidRuntime(839): at android.widget.AdapterView.performItemClick(AdapterView.java:292)
02-04 18:48:07.987: E/AndroidRuntime(839): at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
02-04 18:48:07.987: E/AndroidRuntime(839): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
02-04 18:48:07.987: E/AndroidRuntime(839): at android.widget.AbsListView$1.run(AbsListView.java:3168)
02-04 18:48:07.987: E/AndroidRuntime(839): at android.os.Handler.handleCallback(Handler.java:605)
02-04 18:48:07.987: E/AndroidRuntime(839): at android.os.Handler.dispatchMessage(Handler.java:92)
02-04 18:48:07.987: E/AndroidRuntime(839): at android.os.Looper.loop(Looper.java:137)
02-04 18:48:07.987: E/AndroidRuntime(839): at android.app.ActivityThread.main(ActivityThread.java:4424)
02-04 18:48:07.987: E/AndroidRuntime(839): at java.lang.reflect.Method.invokeNative(Native Method)
02-04 18:48:07.987: E/AndroidRuntime(839): at java.lang.reflect.Method.invoke(Method.java:511)
02-04 18:48:07.987: E/AndroidRuntime(839): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-04 18:48:07.987: E/AndroidRuntime(839): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-04 18:48:07.987: E/AndroidRuntime(839): at dalvik.system.NativeStart.main(Native Method)