FirebaseAuth.getInstance()崩溃并显示"IllegalArgumentException:给定的字符串为空或空". [英] FirebaseAuth.getInstance() crashes with "IllegalArgumentException: Given String is empty or null"

查看:113
本文介绍了FirebaseAuth.getInstance()崩溃并显示"IllegalArgumentException:给定的字符串为空或空".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从我的应用程序创建一个登录系统,但是当我打开它时崩溃.我设法将错误定位到该行

I was trying to create a login system from my app, but it crashes when I open it. I managed to locate the bug to the line

mFirebaseAuth = FirebaseAuth.getInstance();

这对我来说毫无意义.这是代码:

which makes no sense to me. Here is the code:

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Initialize Firebase Auth
    mFirebaseAuth = FirebaseAuth.getInstance();
    mFirebaseUser = mFirebaseAuth.getCurrentUser();

    if (mFirebaseUser == null) {
        // Not logged in, launch the Log In activity
        loadLogInView();
    }
}

private void loadLogInView() {
    Intent intent = new Intent(this, LogInActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);
}

和崩溃报告:

02-20 01:04:45.137 3186-3186/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                 Process: com.maegner.testingfirebase, PID: 3186
                                                 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.maegner.testingfirebase/com.maegner.testingfirebase.MainActivity}: java.lang.IllegalArgumentException: Given String is empty or null
                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
                                                     at android.app.ActivityThread.-wrap12(ActivityThread.java)..............

推荐答案

此异常可能是由错误配置的google-services.json文件引起的.如果api_key丢失,将发生错误.确认您的google-services.json文件包含以下部分:

This exception can be caused by a misconfigured google-services.json file. The error will occur if the api_key is missing. Verify that your google-services.json file contains this section:

  "api_key": [
    {
      "current_key": "AIzaSyDkG-g8hH7T4TV7RrN23ccnRsXp12345678" //<-- your key here
    }
  ],

如果没有,请重新生成google-services.json.

If it does not, regenerate google-services.json.

这篇关于FirebaseAuth.getInstance()崩溃并显示"IllegalArgumentException:给定的字符串为空或空".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆