NullPointerException android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState

Source: Internet
Author: User

Fragment Plus viewpager do tab when easy out of this null pointer exception, see Source:

if (f.msavedviewstate! = null) {    if (result = = null) {        result = new Bundle ();    }    Result.putsparseparcelablearray (            Fragmentmanagerimpl.view_state_tag, f.msavedviewstate);} if (!f.muservisiblehint) {    if (result = = null) {        result = new Bundle ();    }    Only add this if it's not the default value    Result.putboolean (Fragmentmanagerimpl.user_visible_hint_tag, F.muservisiblehint);}

The non-saved state enters the second if null-throw pointer exception.

Add the following code to the fragment to solve the bug:

@Override public void Onsaveinstancestate (bundle outstate) {//first Saving my state, so the bundle wont is empty.outstate. Putstring ("KEY",  "Wbug_value"); Super.onsaveinstancestate (outstate);}

Or:

Class Myfragment extends Fragment {    @Override public    void Onsaveinstancestate (Bundle outstate) {        Super.onsaveinstancestate (outstate);        Setuservisiblehint (True);    }
or use Fragmentstatepageradapter insteadFragmentpageadapter.

NullPointerException android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.