我正在尝试使用Google Firebase实时数据库。我的用户可以创建要在数据库中作为独立表以及在用户类中作为列表进行的事件。这是我用来将事件写入数据库以及发生异常的位置:
mDatabase.child("users").child(ResourceManager.getUser().getId()).child("events").setValue(event);
mDatabase.child("events").setValue(ResourceManager.getAllEvents());
问题是,当我尝试保存创建的事件时,我开始收到一些消息,表明垃圾回收工作了几次,然后在该异常结束时打印了100次相同的异常,然后应用程序重新启动。
06-30 18:38:19.555 15005-15005/tvfriends.kolio.com.tvproba E/AndroidRuntime: at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzav(Unknown Source)
at com.google.firebase.database.DatabaseReference.zza(Unknown Source)
at com.google.firebase.database.DatabaseReference.setValue(Unknown Source)
at tvfriends.kolio.com.tvproba.HostActivity.onClick(HostActivity.java:109)
at android.view.View.performClick(View.java:5609)
at android.view.View$PerformClick.run(View.java:22238)
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:6044)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
同样在顶部异常的末尾,我又得到了一个
06-30 18:38:21.478 15005-15005/tvfriends.kolio.com.tvproba D/Error: ERR: TOTAL BYTES WRITTEN: 13034964
06-30 18:38:21.484 15005-15005/tvfriends.kolio.com.tvproba E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 13035048)
06-30 18:38:21.485 15005-15005/tvfriends.kolio.com.tvproba E/AndroidRuntime: Error reporting crash
android.os.TransactionTooLargeException: data parcel size 13035048 bytes
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:615)
at android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative.java:5100)
at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:97)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1063)
在我的事件类中,我尝试存储以下变量:
private TVEvent tvEvent;
private User host;
private long date;
private String location;
private TVSet tvSet;
private List<User> attending;
private int eventStatus;
TVEvent,TVSet和User中每个都有一个位图以及大多数原始数据。那么,这是什么问题呢?任何帮助深表感谢。
编辑
这是stackoverflow错误:
D/Error: ERR: stack=java.lang.StackOverflowError: stack size 8MB
at java.lang.reflect.Method.invoke(Native Method)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaw(Unknown Source)
at com.google.android.gms.internal.zzaix.zzaD(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source)
at com.google.android.gms.internal.zz
06-30 18:38:21.447 15005-15012/tvfriends.kolio.com.tvproba W/art: Suspending all threads took: 64.352ms
06-30 18:38:21.478 15005-15005/tvfriends.kolio.com.tvproba D/Error: ERR: TOTAL BYTES WRITTEN: 13034964
最佳答案
您尝试使用setValue()
存储的数据大小可能太大,最有可能是由位图数据引起的。
可以使用Parcels在Android组件之间传递数据,但数据量限制为1MB。之所以发生TransactionTooLargeException,是因为某些组件(您的组件之一或处理您的请求的Firebase组件之一)试图发送包含超过1MB数据的包裹。您看到的垃圾收集重复运行的报告是您处理正在请求大量内存的另一个指示。
这个新问题是否意味着您不再寻求your other question的帮助?如果是这样,请取消赏金。
针对您的其他问题发布的代码中的TVSet.compressImage()
方法表明您正在对全尺寸图像进行Base64编码并存储结果。这是您希望存储在数据库中的数据的一部分。这不是FirebaseDatabase的最佳用法。考虑使用FirebaseStorage来存储仅具有文件名或其他标识 key 存储在数据库中的图像。