我正在尝试使用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)
在我的Event类中,我尝试存储这些变量:
private TVEvent tvEvent;
private User host;
private long date;
private String location;
private TVSet tvSet;
private List<User> attending;
private int eventStatus;
TVEvent,TVSet和用户各有一个位图和大多数原始数据。那么这里的问题是什么?非常感谢任何帮助。
修改
这是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
答案 0 :(得分:7)
您尝试使用setValue()
存储的数据大小可能太大,很可能是由位图数据引起的。
可以使用Parcels在Android组件之间传递数据,但数据量限制为1MB。发生TransactionTooLargeException是因为某个组件(您的一个组件或处理您请求的Firebase组件之一)尝试发送包含超过1MB数据的包裹。您看到垃圾收集重复运行的报告是您的处理请求大量内存的另一个迹象。
这个新问题是否意味着您不再寻求your other question的帮助?如果是这样,取消赏金。
为您的其他问题发布的代码中的TVSet.compressImage()
方法显示您是Base64编码完整大小的图像并存储结果。这是您希望存储在数据库中的数据的一部分。这不是FirebaseDatabase的最佳用途。请考虑使用FirebaseStorage存储仅包含存储在数据库中的文件名或其他标识密钥的映像。
答案 1 :(得分:6)
将我保存在Firebase存储上的图像的Uri保存到Firebase数据库时出现此错误。
与@Mwakima一样,您无法将Uri保存到Firebase数据库。
解决方案:将模型类中uri的类型更改为String,从
获取字符串 String uri = taskSnapshot.getDownloadUrl().toString()
从Firebase获取字符串后,使用
将其传递给Uri Uri imageUri = Uri.Parse(<your-uri-as-a-string>);
答案 2 :(得分:2)
至于我,我决定尝试将我的类实例变成原始类型。
我有一个变量,它将保存为URI的图像的URI保存。
private String userName;
private String userProfilePic;
private String userEmail;
private Uri userUid;
private int userFollowersCount = 0;
private int userFollowingCount = 0;
private int age;
private String userStatus;
private String userLikedPostsUID;
private String userSharedPostsUID;
我的交易错误太大了。 但是在将userUid更改为String后,它就像魅力一样。
因此,请尝试将实例保存为原始形式。就像你的例子。尝试改变TvEvent tvEvent&#39;仅以String形式存储tvEvent的UID。
答案 3 :(得分:0)
如果您的文件大小较小且仍在发生,请获取下载uri的Uri全局变量。 mediaUri = taskSnapshot.getDownloadUrl(); attri.put(“media_dwnld_url”,mediaUri.toString());