Xander Xander - 2 months ago 14x
Android Question

firebase tutorial-modifier private is not allowed here

I'm attempting to add login functionality to my android app using Firebase. I'm following the instructions at https://firebase.google.com/docs/auth/android/password-auth, but when I attempt to use the private modifier, Android Studio tells me it's "not allowed here." But if I don't use that modifier, I can't call mAuth in onStart.

Here is my code:

package com.priceelectric.xriley.priceprefab;

import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

public class Login extends AppCompatActivity {

private FirebaseAuth.AuthStateListener mAuthListener;

protected void onCreate(Bundle savedInstanceState) {

private FirebaseAuth mAuth;

mAuth = FirebaseAuth.getInstance();

mAuthListener = new FirebaseAuth.AuthStateListener() {
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if(user != null){
Log.d("loginTag", "onAuthStateChanged:signed_in:" + user.getUid());
Log.d("loginTag", "onAuthStateChanged:signed_out");


public void onStart(){


That's basic Java rule. You cannot use private, public, protected keywords inside methods. You can only set the visibility of a "global" variable as you did for private FirebaseAuth.AuthStateListener mAuthListener;.

Solution: Put private FirebaseAuth mAuth; right below private FirebaseAuth.AuthStateListener mAuthListener;.