Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting a Attempt to invoke virtual method 'android.support.v4.app.FragmentManager android.support.v4.app.FragmentActivity.getSupportFragmentManager()' on a null object reference #114

Open
duartebarbosadev opened this issue Apr 10, 2016 · 3 comments

Comments

@duartebarbosadev
Copy link

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

@IngridMendes-zz
Copy link

Try

if (getActivity() != null) {
//your code
}

@mannan541
Copy link

Cast getActivity() to AppCompatActivity.

That worked for me.

@padmakumar
Copy link

think this was happened in release build, if its because of proguard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants