android 报错,求解决
07-06 18:46:11.046: E/AndroidRuntime(624): FATAL EXCEPTION: main07-06 18:46:11.046: E/AndroidRuntime(624): java.lang.RuntimeException: Unable to pause activity {com.bookread/com.bookread.ItemActivity}: java.lang.NullPointerException
07-06 18:46:11.046: E/AndroidRuntime(624): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3348)
07-06 18:46:11.046: E/AndroidRuntime(624): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3305)
07-06 18:46:11.046: E/AndroidRuntime(624): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3786)
07-06 18:46:11.046: E/AndroidRuntime(624): at android.app.ActivityThread.access$2400(ActivityThread.java:125)
07-06 18:46:11.046: E/AndroidRuntime(624): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2037)
07-06 18:46:11.046: E/AndroidRuntime(624): at android.os.Handler.dispatchMessage(Handler.java:99)
07-06 18:46:11.046: E/AndroidRuntime(624): at android.os.Looper.loop(Looper.java:123)
07-06 18:46:11.046: E/AndroidRuntime(624): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-06 18:46:11.046: E/AndroidRuntime(624): at java.lang.reflect.Method.invokeNative(Native Method)
07-06 18:46:11.046: E/AndroidRuntime(624): at java.lang.reflect.Method.invoke(Method.java:521)
07-06 18:46:11.046: E/AndroidRuntime(624): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-06 18:46:11.046: E/AndroidRuntime(624): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-06 18:46:11.046: E/AndroidRuntime(624): at dalvik.system.NativeStart.main(Native Method)
07-06 18:46:11.046: E/AndroidRuntime(624): Caused by: java.lang.NullPointerException
07-06 18:46:11.046: E/AndroidRuntime(624): at android.support.v4.view.ViewPager.onSaveInstanceState(ViewPager.java:507)
07-06 18:46:11.046: E/AndroidRuntime(624): at android.view.View.dispatchSaveInstanceState(View.java:6068)
07-06 18:46:11.046: E/AndroidRuntime(624): at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:1180)
07-06 18:46:11.046: E/AndroidRuntime(624): at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:1184)
07-06 18:46:11.046: E/AndroidRuntime(624): at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:1184)
07-06 18:46:11.046: E/AndroidRuntime(624): at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:1184)
07-06 18:46:11.046: E/AndroidRuntime(624): at android.view.View.saveHierarchyState(View.java:6051)
07-06 18:46:11.046: E/AndroidRuntime(624): at com.android.internal.policy.impl.PhoneWindow.saveHierarchyState(PhoneWindow.java:1430)
07-06 18:46:11.046: E/AndroidRuntime(624): at android.app.Activity.onSaveInstanceState(Activity.java:1086)
07-06 18:46:11.046: E/AndroidRuntime(624): at android.app.Activity.performSaveInstanceState(Activity.java:1036)
07-06 18:46:11.046: E/AndroidRuntime(624): at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1180)
07-06 18:46:11.046: E/AndroidRuntime(624): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3330)
07-06 18:46:11.046: E/AndroidRuntime(624): ... 12 more --------------------编程问答-------------------- 空指针嘛,仔细看看就行了啊 --------------------编程问答-------------------- 07-06 18:46:11.046: E/AndroidRuntime(624): at android.support.v4.view.ViewPager.onSaveInstanceState(ViewPager.java:507)
这一行空指针啊,新手 --------------------编程问答-------------------- 看下错误信息 对照哪一行进行相应修改啊 --------------------编程问答-------------------- 空指针错误
android.app.Activity.onSaveInstanceState(Activity.java:1086) --------------------编程问答-------------------- 空指向异常,找到定义的地方,看看有没有出现空指向的地方 --------------------编程问答-------------------- V4包的一个BUG,
if (!f.mUserVisibleHint) {
// Only add this if it's not the default value
result.putBoolean(FragmentManagerImpl.USER_VISIBLE_HINT_TAG, f.mUserVisibleHint);
}
加入if (result == null) {
result = new Bundle();
}
详情见http://stackoverflow.com/questions/8748064/starting-activity-from-fragment-causes-nullpointerexception --------------------编程问答-------------------- 07-06 18:46:11.046: E/AndroidRuntime(624): at android.support.v4.view.ViewPager.onSaveInstanceState(ViewPager.java:507)
--------------------编程问答-------------------- 我在android巴士找到的解决方法http://www.apkbus.com/android-59151-2-1.html
它是这样回答的,
在跳转其他activity 或者在关闭当前activity 的时候;如果你的当前activity有用到ViewPager,但是还没有给ViewPager setAdapter ,就会有以上异常;
解决方法:
只要有ViewPager 在界面初始化的时候就必须给ViewPager 设置adapter,不论你当前是否用到。并且一个ViewPager 最好只声明一次,设置一次adapter,不然可能会有的时候界面显示不出来;
(~ o ~)~zZ 按照android巴士的方法 终于解决了。。。纠结死我了。。。
补充:移动开发 , Android