我的应用程序的主要活动扩展了 FragmentActivity 并在暂停和恢复时通过转移到手机上的其他应用程序正确运行。
@Override
protected void onCreate(Bundle savedInstanceState) {
...
..
.
mPagerAdapter = new MyPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mPagerAdapter);
mViewPager.setCurrentItem(PAGE_No / 2);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.my_pager, container, false);
...
..
.
mGridView.setAdapter(new CellAdapter(rootView.getContext(), x,y));
return rootView;
}
但是,当它被 ActivityManager 杀死时(ActivityManager: Process com.androcn.aaa.bbb (pid 16471) has dead.)我收到:Unable to start activity: NullPointerException,从编译器重新启动它:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androcn.aaa.bbb/com.androcn.aaa.bbb.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2351)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$600(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5485)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.androcn.aaa.bbb.MainActivity$MonthViewFragment.onCreate(MainActivity.java:162)
at android.support.v4.app.Fragment.performCreate(Fragment.java:1437)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:877)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1070)
at android.support.v4.app.FragmentManagerImpl.dispatchCreate(FragmentManager.java:1856)
at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:210)
at com.androcn.aaa.bbb.MainActivity.onCreate(MainActivity.java:77)
at android.app.Activity.performCreate(Activity.java:5066)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
... 11 more
如果有人可以帮助我,我将不胜感激。