我在使用ViewPager
时使用垂直setAdapter
我会检查verticalViewPager
和arrayPagerAdapter
是否为空,但是我仍然在少数设备上低于Logcat异常,但在所有设备中都没有。
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Handler android.support.v4.app.FragmentHostCallback.getHandler()' on a null object reference
at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1623)
at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:637)
at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:166)
at com.inheadline.news.view.viewpager.VerticalViewPager.setAdapter(VerticalViewPager.java:278)
at com.inheadline.news.activity.MainActivity.setupViewPager(MainActivity.java:487)
at com.inheadline.news.activity.MainActivity.dataAdded(MainActivity.java:557)
at com.inheadline.news.db.operation.DataSnapshotToDb$AddToDb.onPostExecute(DataSnapshotToDb.java:163)
at com.inheadline.news.db.operation.DataSnapshotToDb$AddToDb.onPostExecute(DataSnapshotToDb.java:138)
at android.os.AsyncTask.finish(AsyncTask.java:679)
at android.os.AsyncTask.access$500(AsyncTask.java:180)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:696)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5546)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
设置视图寻呼机时,这是我的代码:
if (verticalViewPager != null && arrayPagerAdapter != null) {
verticalViewPager.setAdapter(arrayPagerAdapter);
verticalViewPager.setSwipable(true);
verticalViewPager.setOnPageChangeListener(pageChangeListener);
}
上面的代码MainActivity.java:487
是verticalViewPager.setAdapter(arrayPagerAdapter);