问题描述
早上好,当我尝试通过虚拟设备进行注册或登录时出现此错误:
Good morning, I have this error when I try to register or login via my virtual device :
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)
虚拟设备是Xperia Z3 Android 6.0.1 API23
The virtual device is an Xperia Z3 Android 6.0.1 API23
这是LoginActivity.java的代码:
And this is the code of the 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();
}
}
});
我认为错误来自此行:
因为.getMessageget
关于java.lang.NullPointerException
的警告,如错误消息中一样.
Because the .getMessageget
a warning about a java.lang.NullPointerException
, like in the error message.
我在profileImageUrl = taskSnapshot.getDownloadUrl().toString();
处的profileRegistration.java中具有相同的警告:
I have the same warning in the profileRegistration.java at 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();
}
})
您知道是什么原因或如何解决该问题吗?
Any idea what's causing it or how to fix it?
推荐答案
我能够通过将firebase-auth降级为15.0.0来解决此问题
I was able to fix the problem by downgrading firebase-auth to 15.0.0
implementation 'com.google.firebase:firebase-auth:15.0.0'
这篇关于无法将对象转换为JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!