ASNE
ASNE copied to clipboard
Getting a Attempt to invoke virtual method 'android.support.v4.app.FragmentManager android.support.v4.app.FragmentActivity.getSupportFragmentManager()' on a null object reference
Hi I am trying to close the fragment and go back to my Activity when the user is logged in. So I did:
private void initSocialNetwork(SocialNetwork socialNetwork){
getActivity().getSupportFragmentManager().beginTransaction().remove(this).commit();
}
The thing is if the user is previosly connect it works like a charm, but if he loggs in it shows this error:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.support.v4.app.FragmentManager android.support.v4.app.FragmentActivity.getSupportFragmentManager()' on a null object reference
Try
if (getActivity() != null) { //your code }
Cast getActivity() to AppCompatActivity.
That worked for me.
think this was happened in release build, if its because of proguard.