3

I am making a simple app for user registration in firebase. I added two editText for getting email and password from user and button for sign up. I already added a class that extends Application for initialising default firebaseApp. All codes are added below. Help me to sort this error.

MainActivity.java

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

        EditText ed_email, ed_pass;
        Button but_signup;

        ProgressBar progressBar;
        FirebaseAuth auth;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            //FirebaseApp.initializeApp(getApplicationContext());
            //Get Firebase auth instance
            auth = FirebaseAuth.getInstance();


            but_signup = (Button) findViewById(R.id.but_login);

            ed_email = (EditText) findViewById(R.id.ed_email);
            ed_pass = (EditText) findViewById(R.id.ed_pass);


            but_signup.setOnClickListener(this);
        }

        @Override
        protected void onResume() {
            super.onResume();
        }

        @Override
        public void onClick(View v) {
            String email = ed_email.getText().toString().trim();
            String password = ed_pass.getText().toString().trim();

            if (TextUtils.isEmpty(email)) {
                Toast.makeText(getApplicationContext(), "Enter email address!", Toast.LENGTH_SHORT).show();
                return;
            }

            if (TextUtils.isEmpty(password)) {
                Toast.makeText(getApplicationContext(), "Enter password!", Toast.LENGTH_SHORT).show();
                return;
            }

            if (password.length() < 6) {
                Toast.makeText(getApplicationContext(), "Password too short, enter minimum 6 characters!", Toast.LENGTH_SHORT).show();
                return;
            }


            //create user
            auth.createUserWithEmailAndPassword(email, password)
                    .addOnCompleteListener(MainActivity.this, new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            Toast.makeText(MainActivity.this, "createUserWithEmail:onComplete:" + task.isSuccessful(), Toast.LENGTH_SHORT).show();

                            if (!task.isSuccessful()) {
                                Toast.makeText(MainActivity.this, "Authentication failed." + task.getException(),
                                        Toast.LENGTH_SHORT).show();
                            } else {
                                startActivity(new Intent(MainActivity.this, MainActivity.class));
                                finish();
                            }
                        }
                    });
        }
    }

FireApp.java

public class FireApp extends Application {
@Override
public void onCreate() {
    super.onCreate();
    FirebaseApp.initializeApp(getApplicationContext());

}}

logcat

FATAL EXCEPTION: main
Process: com.skapsdevelopment.firebase, PID: 13582
Theme: themes:{default=overlay:com.resurrectionremix.pitchblack, iconPack:com.baranovgroup.nstyle, fontPkg:com.resurrectionremix.pitchblack, com.android.systemui=overlay:com.resurrectionremix.pitchblack, com.android.systemui.navbar=overlay:com.resurrectionremix.pitchblack}
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.skapsdevelopment.firebase/com.skapsdevelopment.firebase.MainActivity}: java.lang.IllegalArgumentException: Given String is empty or null
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2450)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2510)
   at android.app.ActivityThread.-wrap11(ActivityThread.java)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:148)
   at android.app.ActivityThread.main(ActivityThread.java:5461)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
   at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
Caused by: java.lang.IllegalArgumentException: Given String is empty or null
   at com.google.android.gms.common.internal.zzac.zzhz(Unknown Source)
   at com.google.android.gms.internal.zzagt$zza$zza.<init>(Unknown Source)
   at com.google.firebase.auth.FirebaseAuth.zzb(Unknown Source)
   at com.google.firebase.auth.FirebaseAuth.<init>(Unknown Source)
   at com.google.android.gms.internal.zzahe.<init>(Unknown Source)
   at com.google.firebase.auth.FirebaseAuth.zzd(Unknown Source)
   at com.google.firebase.auth.FirebaseAuth.zzc(Unknown Source)
   at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source)
   at com.skapsdevelopment.firebase.MainActivity.onCreate(MainActivity.java:36)
   at android.app.Activity.performCreate(Activity.java:6251)
   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2510) 
   at android.app.ActivityThread.-wrap11(ActivityThread.java) 
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363) 
   at android.os.Handler.dispatchMessage(Handler.java:102) 
   at android.os.Looper.loop(Looper.java:148) 
   at android.app.ActivityThread.main(ActivityThread.java:5461) 
   at java.lang.reflect.Method.invoke(Native Method) 
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
   at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132) 

Please help me to solve this error.

adjuremods
  • 2,938
  • 2
  • 12
  • 17
Subham Kaps
  • 193
  • 1
  • 4
  • 11

2 Answers2

1

This error occurs when the auth key string , commonly known as Api key, is not defined. So check the google-services.json file and put your key in current_key tag.And rebuild the project so that the app uses the api key.

0

The issue for me was that the api_key value in my google_services.json was empty. This was because the default json file generated for me by firebase had no api_key value at all, so I just added one manually to make it work. Adding a random string value here will make the codelab work, but make sure to stop the current run and rebuild the project, otherwise the Android Studio autorun feature will run without updating the json file being used.

You can get your api key from . /console.firebase.google.com/project --> your project --> settings -->general.

and add it to your google_services.json current_key

Zafar Imam
  • 319
  • 3
  • 11