当我尝试将Firebase.CompletionListener添加到我的ValueEventListener时,我收到此错误.
@H_301_5@com.Google.firebase.database.DatabaseException: Failed to parse node with class class c.kristofer.jaxx.MainActivity.MainActivity$2$1$1 at com.Google.androID.gms.internal.firebase_database.zzjd.zza(UnkNown Source) at com.Google.androID.gms.internal.firebase_database.zzjg.zzc(UnkNown Source) at com.Google.firebase.database.DatabaseReference.setValue(UnkNown Source) at c.kristofer.jax2.MainActivity.MainActivity$2$1.onDataChange(MainActivity.java:110) at com.Google.androID.gms.internal.firebase_database.zzfc.zza(UnkNown Source) at com.Google.androID.gms.internal.firebase_database.zzgx.zzdr(UnkNown Source) at com.Google.androID.gms.internal.firebase_database.zzhd.run(UnkNown Source) at androID.os.Handler.handleCallback(Handler.java:751) at androID.os.Handler.dispatchMessage(Handler.java:95) at androID.os.Looper.loop(Looper.java:154) at androID.app.ActivityThread.main(ActivityThread.java:6682) at java.lang.reflect.Method.invoke(Native Method) at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
这是我从here获得的代码:
@H_301_5@fromPath = FirebaseDatabase.getInstance() .getReference() .child("Groups") .child(uID) .child(uID);topath = FirebaseDatabase.getInstance() .getReference() .child("Groups") .child(deeplink.getqueryParameter("groupUID")) .child(uID);userIdpath = FirebaseDatabase.getInstance() .getReference() .child("Groups") .child(deeplink.getqueryParameter("groupUID")) .child(uID) .child("uID");deletePath = FirebaseDatabase.getInstance() .getReference() .child("Groups") .child(uID);fromPath.addValueEventListener(new ValueEventListener() { @OverrIDe public voID onDataChange(DataSnapshot dataSnapshot) { topath.setValue(dataSnapshot.getValue(), new Firebase.CompletionListener() { @OverrIDe public voID onComplete(FirebaseError firebaseError, Firebase firebase) { if (firebaseError != null) { System.out.println("Data Could not be saved. " + firebaseError.getMessage()); } else { System.out.println("Data saved successfully."); userIdpath.setValue(uID); deletePath.removeValue(); } } }); } @OverrIDe public voID onCancelled(DatabaseError databaseError) { } });
当我不使用onCompleteListener时,应用程序工作正常,但当我这样做时崩溃.
解决方法:
实际上,我回答了这个问题,但当时我使用的API现在已经过时了.因此,我建议您使用以下方法:
@H_301_5@private voID moveRecord(DatabaseReference fromPath, final DatabaseReference topath) { ValueEventListener valueEventListener = new ValueEventListener() { @OverrIDe public voID onDataChange(DataSnapshot dataSnapshot) { topath.setValue(dataSnapshot.getValue()).addOnCompleteListener(new OnCompleteListener<VoID>() { @OverrIDe public voID onComplete(@NonNull Task<VoID> task) { if (task.isComplete()) { Log.d(TAG, "Success!"); } else { Log.d(TAG, "copy Failed!"); } } }); } @OverrIDe public voID onCancelled(DatabaseError databaseError) {} }; fromPath.addListenerForSingleValueEvent(valueEventListener);}总结
以上是内存溢出为你收集整理的如何在Firebase实时数据库中将记录从一个位置复制到另一个位置?全部内容,希望文章能够帮你解决如何在Firebase实时数据库中将记录从一个位置复制到另一个位置?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)