Failed to turn object into JSON

戏子无情 提交于 2020-01-03 14:12:10

问题


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)

The virtual device is an Xperia Z3 Android 6.0.1 API23

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();
        }
    }
});

I think the error comes from this line :

Because the .getMessageget a warning about a java.lang.NullPointerException, like in the error message.

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?


回答1:


For me the solution was to delete the local data (long press the app in the app drawer, then app info -> storage -> clear data) and restart the app




回答2:


I was able to fix the problem by downgrading firebase-auth to 15.0.0

implementation 'com.google.firebase:firebase-auth:15.0.0'



回答3:


First Log Your ErrorLike Below:

Log.v("Tag",""+e.task.getException().getMessage());

If that Works then add ""+ to your toast message. If not Try with .toString() after .getMessage() in Log.




回答4:


I was having a similar issue (null pointer) recently with Firebase's Auth library. The issue was that I had updated to the latest Firebase dependencies (which are now all at 15+ and are unique), but I had forgot to update my google services dependency in the root gradle file (version 3.3.1 as of typing this). Make sure each of your dependencies is the latest with the correct version number and that your google services is updated as well. It may be a requirement spread throughout each of Firebase's dependencies.



来源:https://stackoverflow.com/questions/50265988/failed-to-turn-object-into-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!