Skip to content Skip to sidebar Skip to footer

Android.support.v4.app.fragmentmanagerimpl Catch Nullpointerexception?

I need catch NullPointerException by FragmentManagerImpl. But try ... catch does not work. How to catch explicit NullPointerException on getItem()? ....... try {

Solution 1:

The code you posted basically works. Your problem lies elsewhere. Edit your post and show us the code around ActivityThread.java:5257.

For your reference this code shows what you were trying to do in public Fragment getItem(int position)... throw the exception you want and that it can be caught.

package org.jf;

publicclassSomeClass {

    publicstaticvoidmain(String[] args) {
        newSomeClass();
    }

    publicSomeClass() {
        try {

            AClassx=newAClass();
            x.getItem(1);
        } catch (Exception e) {

            System.out.println("Caught");
        }
    }

    classAClass {
        public Object getItem(int position) {
            inttraining=1;
            Objectfragment=null;
            switch (training) {
                case1:
//                    fragment = getTFragment(position);
                    fragment = null;
                    break;
                default:
                    break;
            }

            if (fragment == null) {
                thrownewRuntimeException();
            }

            return fragment;
        }
    }
}

Post a Comment for "Android.support.v4.app.fragmentmanagerimpl Catch Nullpointerexception?"