我在一个活动中具有以下功能
public void AppExit()
{
Editor edit = preferences.edit();
edit.putString("pref_code", "");
edit.commit();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);
}
在自己的活动中正常工作。我想称这为另一项活动。我也创建了类实例如下
Home hm = new Home();
hm.AppExit();
但它越来越错误
06-29 19:41:06.024: E/AndroidRuntime(583): FATAL EXCEPTION: main
06-29 19:41:06.024: E/AndroidRuntime(583): java.lang.NullPointerException
06-29 19:41:06.024: E/AndroidRuntime(583): at android.app.Activity.startActivityForResult(Activity.java:2827)
06-29 19:41:06.024: E/AndroidRuntime(583): at android.app.Activity.startActivity(Activity.java:2933)
06-29 19:41:06.024: E/AndroidRuntime(583): at com.mythrii.timeApp.Home.AppExit(Home.java:219)
06-29 19:41:06.024: E/AndroidRuntime(583): at com.mythrii.timeApp.AdminPage.onOptionsItemSelected(AdminPage.java:205)
06-29 19:41:06.024: E/AndroidRuntime(583): at android.app.Activity.onMenuItemSelected(Activity.java:2205)
06-29 19:41:06.024: E/AndroidRuntime(583): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:748)
06-29 19:41:06.024: E/AndroidRuntime(583): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
06-29 19:41:06.024: E/AndroidRuntime(583): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
06-29 19:41:06.024: E/AndroidRuntime(583): at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
06-29 19:41:06.024: E/AndroidRuntime(583): at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
06-29 19:41:06.024: E/AndroidRuntime(583): at android.view.View$PerformClick.run(View.java:9080)
06-29 19:41:06.024: E/AndroidRuntime(583): at android.os.Handler.handleCallback(Handler.java:587)
06-29 19:41:06.024: E/AndroidRuntime(583): at android.os.Handler.dispatchMessage(Handler.java:92)
06-29 19:41:06.024: E/AndroidRuntime(583): at android.os.Looper.loop(Looper.java:130)
06-29 19:41:06.024: E/AndroidRuntime(583): at android.app.ActivityThread.main(ActivityThread.java:3683)
06-29 19:41:06.024: E/AndroidRuntime(583): at java.lang.reflect.Method.invokeNative(Native Method)
06-29 19:41:06.024: E/AndroidRuntime(583): at java.lang.reflect.Method.invoke(Method.java:507)
06-29 19:41:06.024: E/AndroidRuntime(583): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-29 19:41:06.024: E/AndroidRuntime(583): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-29 19:41:06.024: E/AndroidRuntime(583): at dalvik.system.NativeStart.main(Native Method)
有谁能够帮我…