Friday, June 22, 2012

NullPointerException of ViewPager when change orientation

In my last exercise of "ViewPager", when change orientation, NullPointerException will be thrown in onSaveInstanceState()!

May be it's a bug in ViewPager. Note the class ViewPager is currently under early design and development. May be it will be fixed in later updates.

At this moment, my solution is to comment the statement to call super.onSaveInstanceState(outState).

 @Override
 protected void onSaveInstanceState(Bundle outState) {
  //super.onSaveInstanceState(outState);
  outState.putInt("tab", getActionBar().getSelectedNavigationIndex());
 }


Next:
- Communication between Fragments in ViewPager

2 comments:

  1. My logcat
    any help??

    10-18 00:44:33.649: E/AndroidRuntime(4524): FATAL EXCEPTION: main
    10-18 00:44:33.649: E/AndroidRuntime(4524): java.lang.NullPointerException
    10-18 00:44:33.649: E/AndroidRuntime(4524): at android.support.v4.app.BackStackRecord.doAddOp(BackStackRecord.java:352)
    10-18 00:44:33.649: E/AndroidRuntime(4524): at android.support.v4.app.BackStackRecord.add(BackStackRecord.java:347)
    10-18 00:44:33.649: E/AndroidRuntime(4524): at android.support.v4.app.FragmentPagerAdapter.instantiateItem(FragmentPagerAdapter.java:99)
    10-18 00:44:33.649: E/AndroidRuntime(4524): at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:692)
    10-18 00:44:33.649: E/AndroidRuntime(4524): at android.support.v4.view.ViewPager.populate(ViewPager.java:821)
    10-18 00:44:33.649: E/AndroidRuntime(4524): at android.support.v4.view.ViewPager.populate(ViewPager.java:772)
    10-18 00:44:33.649: E/AndroidRuntime(4524): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1234)
    10-18 00:44:33.649: E/AndroidRuntime(4524): at android.view.View.measure(View.java:15172)
    10-18 00:44:33.649: E/AndroidRuntime(4524): at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
    10-18 00:44:33.649: E/AndroidRuntime(4524): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
    10-18 00:44:33.649: E/AndroidRuntime(4524): at android.view.View.measure(View.java:15172)
    10-18 00:44:33.649: E/AndroidRuntime(4524): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    10-18 00:44:33.649: E/AndroidRuntime(4524): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    10-18 00:44:33.649: E/AndroidRuntime(4524): at android.view.View.measure(View.java:15172)
    10-18 00:44:33.649: E/AndroidRuntime(4524): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)

    ReplyDelete
  2. my LOG please help me in this week only

    06-03 05:05:53.184 22776-22776/com.example.dude.myapp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.dude.myapp, PID: 22776
    java.lang.NullPointerException: Attempt to invoke virtual method 'void com.example.dude.myapp.TextFragment.b_updateText(java.lang.String)' on a null object reference
    at com.example.dude.myapp.ImageFragment$1.onClick(ImageFragment.java:78)
    at android.view.View.performClick(View.java:4756)
    at android.view.View$PerformClick.run(View.java:19749)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5221)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

    ReplyDelete