6

I am trying to use google firebase realtime database. My users can create events which I want to have on the database as a separate table as well as in the user class as a list. This is what I use to write the events to the database and where the exception occurs:

mDatabase.child("users").child(ResourceManager.getUser().getId()).child("events").setValue(event);

mDatabase.child("events").setValue(ResourceManager.getAllEvents());

The problem is that when I try to save the created event I start getting messages that the garbage collection is working few times and after that the same exception printed 100 times at the end of it the app restarts.

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)

Also at the end of the top Exception I get another one

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)

In my Event class I have this variables which I try to store:

private TVEvent tvEvent;
private User host;
private long date;
private String location;
private TVSet tvSet;
private List<User> attending;
private int eventStatus;

TVEvent, TVSet and User have one bitmap each in them and mostle primitive data. So what is the problem here? Any help is deeply appreciated.

EDIT

Here is the stackoverflow error:

 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
Nikola
  • 890
  • 1
  • 11
  • 35
  • Where is the StackOverflowError that you mention in the title? – Travis Christian Jun 30 '16 at 16:12
  • It is nothing special. I guess it has something to do with the garbage collection before the exception. – Nikola Jun 30 '16 at 16:23
  • Possible duplicate of [What to do on TransactionTooLargeException](http://stackoverflow.com/questions/11451393/what-to-do-on-transactiontoolargeexception) – petey Jun 30 '16 at 16:44
  • I think your event(s) are the problem as they are not allowed Firebase values. While setValue takes an Object as param there is no checking on the types you can actually store with setValue. You can only put String, Long, Double, Boolean, Map and List into Firebase values (see: firebase.google.com/docs/database/android/read-and-write) – Peter Jul 28 '17 at 15:59

4 Answers4

7

The size of the data you are attempting to store with setValue() is probably too large, most likely caused by the bitmap data.

Data can be passed between Android components using Parcels, but the amount of data is limited to 1MB. The TransactionTooLargeException occurred because some component, either one of yours or one of the Firebase components handling your requests, attempted to send a parcel that contained more than 1MB of data. The reports you see of garbage collection running repeatedly is another indication that your processing is requesting large amounts of memory.

Does this new question mean you are no longer seeking help with your other question? If so, cancel the bounty.

The TVSet.compressImage() method in the code posted for your other question shows that you are Base64 encoding a full size image and storing the result. This is part of the data you are hoping to store in your database. This is not the best use of FirebaseDatabase. Consider using FirebaseStorage to store the images with only the file name or other identifying key stored in your database.

Community
  • 1
  • 1
Bob Snyder
  • 37,759
  • 6
  • 111
  • 158
  • 1
    thumbsup for researching the poster's other questions! – petey Jun 30 '16 at 16:47
  • Thanks for making things clear, but I still don't have any idea why this happens. Yes, probably the bitmaps are way too big but I don't need them in the database as they are saved in storage as you wrote. And I have the @Exclude tag around them. What can I do to make it work? – Nikola Jun 30 '16 at 17:41
  • 1
    @Nikola: I haven't used [@Exclude](https://developers.google.com/android/reference/com/google/firebase/database/Exclude). I think you need to put it on`private String imageFile` not on `getImage()`. If that doesn't help, try setting field `imageFile` to some small dummy value just to see if the error goes away. – Bob Snyder Jun 30 '16 at 17:52
  • I don't think this answer applies to the question. The problem is probably not that the transaction is too large but rather that Nikola is trying to store incompatible types of objects in Firebase (event(s)). You can only put String, Long, Double, Boolean, Map and List into Firebase values (see: firebase.google.com/docs/database/android/read-and-write) – Peter Jul 28 '17 at 16:06
  • @Peter: `set()` also accepts an [appropriately defined object](https://firebase.google.com/docs/database/android/read-and-write): _Pass a custom Java object, if the class that defines it has a default constructor that takes no arguments and has public getters for the properties to be assigned_. This is the case here for the `Event` class. See also the description of `setValue()` in the [reference documentation](https://firebase.google.com/docs/reference/android/com/google/firebase/database/DatabaseReference). – Bob Snyder Jul 28 '17 at 17:05
6

Got this error when saving the Uri of an Image I was saving on Firebase Storage to Firebase Database.

Like @Mwakima mentioned, you cannot save a Uri to Firebase Database.

Solution: Change the type of your uri in the model class to String, get the String from

String uri = taskSnapshot.getDownloadUrl().toString()

When you get the String back from Firebase, pass it to a Uri using

Uri imageUri = Uri.Parse(<your-uri-as-a-string>);

Ojonugwa Jude Ochalifu
  • 26,627
  • 26
  • 120
  • 132
  • But why its size is so big then? Isn't it just like a string? Or does it have the image itself with some encoding? – ninbit Aug 16 '18 at 09:02
2

As for me I decided to try and make my instances of the class into primitive type.

I had a variable that was holding the URI of an image saved as a 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;

I got the Transaction too large error. But after changing userUid into a String it worked like a charm.

So try to save your instances into a primitive form. Like in your example. Try to change 'TvEvent tvEvent' to store only the UID of the tvEvent in a String form.

  • 1
    I had the exact same problem with using Uri instead of String. Turns out there is no checking done on what you try and save in Firebase with setValue and updateChildren. You can only put String, Long, Double, Boolean, Map and List into Firebase values (see: firebase.google.com/docs/database/android/read-and-write) – Peter Jul 28 '17 at 16:01
0

In case if your file is of less size and if it is still happening, get Uri global variable of the download uri in that. mediaUri = taskSnapshot.getDownloadUrl(); attri.put("media_dwnld_url", mediaUri.toString());

Vikash Sharma
  • 539
  • 8
  • 13