由于getUid的Firebase引用导致App崩溃OnCreate方法

时间:2019-03-17 07:35:16

标签: android firebase firebase-authentication

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mAuth = FirebaseAuth.getInstance();
    currentUserId = mAuth.getCurrentUser().getUid();       //Crashes after adding this line
}

@Override
protected void onStart() {
    super.onStart();

    FirebaseUser currentUser = mAuth.getCurrentUser();
    if (currentUser == null) {
        SendUserToLoginActivity();
    }
}

我在其他应用程序上也使用了类似的代码,但是它们运行良好,但是从今天开始所有应用程序都崩溃了,代码的使用是否有问题或是firebase的错误?

这里的日志

 Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getUid()' on a null object reference
    at com.example.werenews.MainActivity.onCreate(MainActivity.java:30)
    at android.app.Activity.performCreate(Activity.java:6672)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2612

0 个答案:

没有答案