Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Firebase_Auth_API在API 23上不可用_Java_Android_Firebase_Android Edittext_Firebase Authentication - Fatal编程技术网

Java Firebase_Auth_API在API 23上不可用

Java Firebase_Auth_API在API 23上不可用,java,android,firebase,android-edittext,firebase-authentication,Java,Android,Firebase,Android Edittext,Firebase Authentication,我创建了一个EditText,用于捕获用户名和密码,以便稍后存储在Firebase中。在运行API26的AVD中,我没有任何问题。但是,我最近创建了一个运行API 23的AVD,它在我创建的“loggedInAuth”变量上返回null。根据我的理解和研究,这是Firebase的一个bug。我不确定是否可以在API上运行此代码尝试此操作并检查是否记录了用户id mAuth.createUserWithEmailAndPassword(mNewFirebaseUserEmail, mNewFire

我创建了一个EditText,用于捕获用户名和密码,以便稍后存储在Firebase中。在运行API26的AVD中,我没有任何问题。但是,我最近创建了一个运行API 23的AVD,它在我创建的“loggedInAuth”变量上返回null。根据我的理解和研究,这是Firebase的一个bug。我不确定是否可以在API上运行此代码尝试此操作并检查是否记录了用户id

mAuth.createUserWithEmailAndPassword(mNewFirebaseUserEmail, mNewFirebaseUserPassword)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        // Sign in success, update UI with the signed-in user's information
                        Log.d(TAG, "createUserWithEmail:success");
                        FirebaseUser user = mAuth.getCurrentUser();
                        Log.d(TAG, "user:"+user.getUid());
                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w(TAG, "createUserWithEmail:failure", task.getException());
                        Toast.makeText(EmailPasswordActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }

                }
            });

我正在阅读更多关于它的信息,它似乎与Firebase AUTH API有关,而Firebase AUTH API在此设备上不可用。为什么会是这样?是因为它是一个模拟器吗?是的,可能是在真实设备中进行测试。我看到你的FirebaseAuth是空的。那么我应该假设在真实的设备上,任何运行API 23的人都会有这个问题吗?
public void onSignupSuccess() {
    signupButton.setEnabled(true);
    //not sure why this line is here
    setResult(RESULT_OK, null);
    //this line below actually creates the user in Firebase; does not write or save to any locations
    mAuth.createUserWithEmailAndPassword(mNewFirebaseUserEmail, mNewFirebaseUserPassword)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d(TAG, "signInWithEmail:onComplete:" + task.isSuccessful());
                    FirebaseAuth loggedInAuth = FirebaseAuth.getInstance();
                    NULL BEING THROWN HERE
                    String ID = loggedInAuth.getCurrentUser().getUid();
                    //TODO: Update handling of display name
                    String displayName = mAuth.getCurrentUser().getUid();
                    HashMap<String, Object> id = new HashMap<>();
                    id.put("user_id", ID);
                    id.put("display_name", displayName);
                    mUserRef.child(ID).updateChildren(id);

                    // If sign in fails, display a message to the user. If sign in succeeds
                    // the auth state listener will be notified and logic to handle the
                    // signed in user can be handled in the listener.
                    if (!task.isSuccessful()) {
                        Log.w(TAG, "signInWithEmail:failed", task.getException());
                        Toast.makeText(SignupActivity.this, "Authentication Failed with Email",
                                Toast.LENGTH_SHORT).show();
                    }
                }
            });
}
 09-30 10:06:25.105 2456-2456/com.troychuinard.fanpolls E/AndroidRuntime: FATAL EXCEPTION: main
                                                                         Process: com.troychuinard.fanpolls, PID: 2456
                                                                         java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getUid()' on a null object reference
                                                                             at com.troychuinard.fanpolls.SignupActivity$5.onComplete(SignupActivity.java:280)
                                                                             at com.google.android.gms.tasks.zzf.run(Unknown Source)
                                                                             at android.os.Handler.handleCallback(Handler.java:739)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                             at android.os.Looper.loop(Looper.java:148)
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                             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)
mAuth.createUserWithEmailAndPassword(mNewFirebaseUserEmail, mNewFirebaseUserPassword)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        // Sign in success, update UI with the signed-in user's information
                        Log.d(TAG, "createUserWithEmail:success");
                        FirebaseUser user = mAuth.getCurrentUser();
                        Log.d(TAG, "user:"+user.getUid());
                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w(TAG, "createUserWithEmail:failure", task.getException());
                        Toast.makeText(EmailPasswordActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }

                }
            });