无法将对象转换为JSON

5 java android json nullpointerexception firebase-authentication

早上好,当我尝试注册或通过我的虚拟设备登录时出现此错误:

E/StorageHelpers: Failed to turn object into JSON   java.lang.NullPointerException: Attempt to invoke virtual method   'org.json.JSONObject com.google.firebase.auth.internal.zzm.zzbf()' on a null  object reference at com.google.firebase.auth.internal.zzz.zzi(Unknown Source) at  com.google.firebase.auth.internal.zzz.zzg(Unknown Source) at com.google.firebase.auth.FirebaseAuth.zza(Unknown Source) at com.google.firebase.auth.FirebaseAuth$zza.zza(Unknown Source) at com.google.firebase.auth.api.internal.zzbq.zzaa(Unknown Source) at com.google.firebase.auth.api.internal.zzcy.zzal(Unknown Source) at  com.google.firebase.auth.api.internal.zzcy.zza(Unknown Source) at com.google.firebase.auth.api.internal.zzdb.zza(Unknown Source) at com.google.firebase.auth.api.internal.zzci.dispatchTransaction(Unknown Source) at com.google.android.gms.internal.firebase_auth.zzb.onTransact(Unknown Source) at android.os.Binder.execTransact(Binder.java:453)
Run Code Online (Sandbox Code Playgroud)

虚拟设备是Xperia Z3 Android 6.0.1 API23

这是LoginActivity.java的代码:

 mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
    @Override
    public void onComplete(@NonNull Task<AuthResult> task) {
        progressBar.setVisibility(View.GONE);
        if (task.isSuccessful()) {
            finish();
            Intent intent = new Intent(LoginActivity.this, menuPrincipal.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        } else {
            Toast.makeText(getApplicationContext(), task.getException().getMessage(), Toast.LENGTH_SHORT).show();
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

我认为错误来自这一行:

在此输入图像描述

因为有关.getMessagegeta的警告java.lang.NullPointerException,就像在错误消息中一样.

我在profileRegistration.java中有相同的警告profileImageUrl = taskSnapshot.getDownloadUrl().toString();:

private void uploadImageToFirebaseStorage(){
    StorageReference profilImageRef =    FirebaseStorage.getInstance().getReference("profilepics/" +   System.currentTimeMillis() + ".jpg");

    if (uriProfileImage != null) {
        progressBarImage.setVisibility(View.VISIBLE);
        profilImageRef.putFile(uriProfileImage)
                .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                        progressBarImage.setVisibility(View.GONE);
                        profileImageUrl = taskSnapshot.getDownloadUrl().toString();
                    }
                })
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

知道是什么导致它或如何解决它?

Tap*_*tro 0

首先记录您的错误如下:

Log.v("Tag",""+e.task.getException().getMessage());
Run Code Online (Sandbox Code Playgroud)

如果有效,请添加""+到您的 toast 消息中。如果没有,请在日志中尝试使用.toString()after .getMessage()