This is my Stacktrace:
FATAL EXCEPTION: main
java.lang.NullPointerException
at com.example.test.fragments.LoadingFragment$1.run(LoadingFragment.java:66)
at a
Replace this getFragmentManager()
with this getSupportFragmentManager()
and also make sure that your activity extends FragmentActivity
From android.support.v4.app.Fragment
source:
// The fragment manager we are associated with. Set as soon as the
// fragment is used in a transaction; cleared after it has been removed
// from all transactions.
FragmentManagerImpl mFragmentManager;
Apparently getFragmentManager()
returns support version of fragment manager but only during a transaction (or parent fragment's child fragment manager).
I'm going to use this:
public FragmentManager getHostFragmentManager() {
FragmentManager fm = getFragmentManager();
if (fm == null && isAdded()) {
fm = ((AppCompatActivity)getActivity()).getSupportFragmentManager();
}
return fm;
}
CASE: When you need to call Fragment(Child fragment) from another Fragment(Parent Fragment)
always use getChildFragmentManager()
instead of getFragmentManager()
inside your Parent Fragment.
After cleaning and rebuilding my project aswell as restarting my testing device, this worked again somehow.