0

So I was trying to get my first app up and running and I ran in to a problem when I tried debugging it on my phone. The error states

Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.stuff.morestuff. Make sure to call FirebaseApp.initializeApp(Context) first.
        at com.google.firebase.FirebaseApp.getInstance(SourceFile:218)
        at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source:1)
        at com.stuff.morestuff.MainActivity.<init>(MainActivity.java:13)

And I've tried using FirebaseApp.initializeApp(this) but it still throws the same error.

public class MainActivity extends AppCompatActivity {

    private FirebaseAuth mAuth;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //I've tried using this too but it didn't change anything, still the same error
        //FirebaseApp.initializeApp(this);
        mAuth = FirebaseAuth.getInstance();
    }

    @Override
    public void onStart() {
        super.onStart();
        // Check if user is signed in (non-null) and update UI accordingly.
        FirebaseUser currentUser = mAuth.getCurrentUser();

        if(currentUser == null){
            Intent startIntent = new Intent(MainActivity.this, StartActivity.class);
            startActivity(startIntent);
        }
    }
}

Did I miss something?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Mark Denom
  • 987
  • 1
  • 8
  • 24
  • Your stacktrace doesn't match your code. The stacktrace says you attempted to initialize `mAuth` during the MainActivity's initialization. Your code shows it being instantiated correctly. – TheWanderer Feb 02 '19 at 22:53
  • Check [this](https://stackoverflow.com/questions/40081539/default-firebaseapp-is-not-initialized) link, there's several solution that might work – Vucko Feb 02 '19 at 22:54
  • Okay so I'm not crazy, that's what I thought yet it seems to do this, do you reckon a restart of the IDE will do? – Mark Denom Feb 02 '19 at 22:55

1 Answers1

0

This solution worked for me. **REMARKS Check the comments to the solution if you want to use 4.1.0

https://stackoverflow.com/a/52136056/7808468

Mark Denom
  • 987
  • 1
  • 8
  • 24