java - gson.toJson(Set<CustomObject>) is not working -


i have customclass object having uri,int,& other customclass data.i want save set in shared peference using gson library.

final customclass obj1 = new customclass.builder().msourceuri(downloaduri)                 .mdestinationuri(destinationuri)                 .metadata(metadata1).build(); set<customclass> set = new hashset<customclass>(); set.add(obj1); set.add(obj2);..etc     gson gson = new gson();             type type = new typetoken<set<customclass>>() {}.gettype();             string json = gson.tojson(set,type);         editor = sharedpreferences.edit();         editor.putstring("sharekey", json);         editor.commit(); 

but gson.tojson() not returning & application crashing. gc called contineously. not using generic types in application. when tried sample application student class data, working fine. failing customclass object please in resolving this. have copied logs below.

customobject class:

public class customobject implements comparable<customobject> {     private int mdownloadstate;     private int mdownloadid;     private uri muri;         private uri mdestinationuri;     private retrypolicy mretrypolicy;     private customobjectmetadata metadata;     private boolean mcanceled = false;     private customobjectqueue mrequestqueue;     private downloadstatuslistener mdownloadlistener;     private hashmap<string, string> mcustomheader;     private enum priority {         low,         normal,         high,         immediate     }      private priority mpriority = priority.normal;     public static class builder {         private uri msourceuri;         private uri mdestinationuri;         private customobjectmetadata metadata;          public builder builder () {             return this;         }         public builder msourceuri(uri muri) {             this.msourceuri = muri;             return this;         }         public builder mdestinationuri(uri muri) {             this.mdestinationuri = muri;             return this;         }         public builder metadata(customobjectmetadata metadata) {             this.metadata = metadata;             return this;         }          public customobject build() {             return new customobject(this);         }     }     public customobject (builder builder) {         this.muri = builder.msourceuri;         this.mdestinationuri = builder.mdestinationuri;         this.metadata = builder.metadata;          if (this.muri == null) {             throw new nullpointerexception();         }          string scheme = this.muri.getscheme();         if (scheme == null || (!scheme.equals("http") && !scheme.equals("https"))) {             throw new illegalargumentexception("can download http/https uris: " + muri);         }         mcustomheader = new hashmap<string, string>();         mdownloadstate = idownloadmanager.status_pending;     }     public customobject () {     }      private priority getpriority() {         return mpriority;     }       private customobject setpriority(priority priority) {         mpriority = priority;         return this;     }       public customobject addcustomheader(string key, string value) {         mcustomheader.put(key, value);         return this;     }       /**      * associates request given queue. request queue notified when      * request has finished.      */     void setcustomobjectqueue(customobjectqueue downloadqueue) {         mrequestqueue = downloadqueue;     }      public retrypolicy getretrypolicy() {         return mretrypolicy == null ? new defaultretrypolicy() : mretrypolicy;     }      private customobject setretrypolicy(retrypolicy mretrypolicy) {         this.mretrypolicy = mretrypolicy;         return this;     }      /**      * sets download id of request.  used {@link customobjectqueue}.      */     final void setdownloadid(int downloadid) {         mdownloadid = downloadid;     }      final int getdownloadid() {         return mdownloadid;     }      int getdownloadstate() {         return mdownloadstate;     }      void setdownloadstate(int mdownloadstate) {         //update meta state;          this.mdownloadstate = mdownloadstate;         getmetadata().setstatus(mdownloadstate);      }     public customobjectmetadata getmetadata() {         return metadata == null ? new customobjectmetadata() : this.metadata;     }      public customobject setmetadata(customobjectmetadata metainfo) {         this.metadata = metainfo;         this.metadata.setsourceuri(this.getsourceuri());         this.metadata.setdestinationuri(this.getdestinationuri());         return this;     }  //    public customobjectmetadata getmetadata() { //        return metadata; //    }      downloadstatuslistener getdownloadlistener() {         return mdownloadlistener;     }      public customobject setdownloadlistener(downloadstatuslistener downloadlistener) {         this.mdownloadlistener = downloadlistener;         return this;     }      public uri getsourceuri() {         return muri;     }      public customobject setsourceuri(uri muri) {         this.muri = muri;         return this;     }      public uri getdestinationuri() {         return mdestinationuri;     }      public customobject setdestinationuri(uri destinationuri) {         this.mdestinationuri = destinationuri;         return this;     }      //package-private methods.      /**      * mark request canceled.  no callback delivered.      */     public void cancel() {         mcanceled = true;     }      public void canceldownload(int mdownloadid) {         mrequestqueue.cancel(mdownloadid);     }      /**      * returns true if request has been canceled.      */     public boolean iscanceled() {         return mcanceled;     }      /**      * returns custom headers set user      *      * @return      */     hashmap<string, string> getcustomheaders() {         return mcustomheader;     }       void finish() {         mrequestqueue.finish(this);     }      @override     public int compareto(customobject other) {         priority left = this.getpriority();         priority right = other.getpriority();          // high-priority requests "lesser" sorted front.         // equal priorities sorted sequence number provide fifo ordering.         return left == right ?                 this.mdownloadid - other.mdownloadid :                 right.ordinal() - left.ordinal();     } }   log :          suspending threads took: 191.070ms     09-21 12:43:04.827    4425-4440/com.mani.myapp.app w/art﹕ suspending threads took: 10.456ms     09-21 12:43:04.844    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 37651(1332kb) allocspace objects, 0(0b) los objects, 18% free, 6mb/7mb, paused 12.266ms total 49.456ms     09-21 12:43:05.029    4425-4445/com.mani.myapp.app i/art﹕ background partial concurrent mark sweep gc freed 69049(2mb) allocspace objects, 20(320kb) los objects, 37% free, 6mb/10mb, paused 9.733ms total 124.986ms     09-21 12:43:05.308    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 87448(2mb) allocspace objects, 61(976kb) los objects, 21% free, 7mb/9mb, paused 11.171ms total 66.163ms     09-21 12:43:05.445    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 45643(1402kb) allocspace objects, 32(512kb) los objects, 19% free, 7mb/9mb, paused 7.924ms total 50.964ms     09-21 12:43:05.666    4425-4445/com.mani.myapp.app i/art﹕ background partial concurrent mark sweep gc freed 79067(2mb) allocspace objects, 54(864kb) los objects, 34% free, 7mb/11mb, paused 10.303ms total 140.975ms     09-21 12:43:05.913    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 95791(2mb) allocspace objects, 60(960kb) los objects, 19% free, 8mb/10mb, paused 9.476ms total 59.863ms     09-21 12:43:06.057    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 48515(1430kb) allocspace objects, 31(496kb) los objects, 17% free, 8mb/10mb, paused 10.450ms total 56.711ms     09-21 12:43:06.291    4425-4445/com.mani.myapp.app i/art﹕ background partial concurrent mark sweep gc freed 88851(2mb) allocspace objects, 58(928kb) los objects, 32% free, 8mb/12mb, paused 10.302ms total 159.924ms     09-21 12:43:06.545    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 96048(2mb) allocspace objects, 61(976kb) los objects, 18% free, 8mb/10mb, paused 10.662ms total 64.854ms     09-21 12:43:06.697    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 47669(1412kb) allocspace objects, 31(496kb) los objects, 16% free, 9mb/10mb, paused 10.732ms total 62.647ms     09-21 12:43:06.916    4425-4440/com.mani.myapp.app w/art﹕ suspending threads took: 91.896ms     09-21 12:43:06.924    4425-4445/com.mani.myapp.app w/art﹕ suspending threads took: 7.190ms     09-21 12:43:06.940    4425-4445/com.mani.myapp.app i/art﹕ background partial concurrent mark sweep gc freed 59016(1610kb) allocspace objects, 32(512kb) los objects, 30% free, 9mb/13mb, paused 16.344ms total 167.829ms     09-21 12:43:07.211    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 96708(2mb) allocspace objects, 58(928kb) los objects, 17% free, 9mb/11mb, paused 10.546ms total 74.644ms     09-21 12:43:07.344    4425-4440/com.mani.myapp.app w/art﹕ suspending threads took: 12.374ms     09-21 12:43:07.352    4425-4445/com.mani.myapp.app w/art﹕ suspending threads took: 7.494ms     09-21 12:43:07.367    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 52606(1436kb) allocspace objects, 28(448kb) los objects, 16% free, 9mb/11mb, paused 16.669ms total 65.283ms     09-21 12:43:07.641    4425-4445/com.mani.myapp.app i/art﹕ background partial concurrent mark sweep gc freed 98017(2mb) allocspace objects, 60(960kb) los objects, 27% free, 10mb/14mb, paused 11.952ms total 187.184ms     09-21 12:43:07.924    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 104842(2mb) allocspace objects, 57(912kb) los objects, 15% free, 10mb/12mb, paused 11.145ms total 71.245ms     09-21 12:43:08.084    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 51645(1413kb) allocspace objects, 28(448kb) los objects, 14% free, 10mb/12mb, paused 11.965ms total 66.246ms     09-21 12:43:08.362    4425-4440/com.mani.myapp.app w/art﹕ suspending threads took: 32.383ms     09-21 12:43:08.371    4425-4445/com.mani.myapp.app w/art﹕ suspending threads took: 9.035ms     09-21 12:43:08.392    4425-4445/com.mani.myapp.app i/art﹕ background partial concurrent mark sweep gc freed 99862(2mb) allocspace objects, 57(952kb) los objects, 26% free, 11mb/15mb, paused 19.062ms total 219.195ms     09-21 12:43:08.651    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 94185(2mb) allocspace objects, 51(1020kb) los objects, 14% free, 11mb/13mb, paused 10.410ms total 70.971ms     09-21 12:43:08.805    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 47061(1378kb) allocspace objects, 25(500kb) los objects, 13% free, 11mb/13mb, paused 11.346ms total 63.690ms     09-21 12:43:09.120    4425-4445/com.mani.myapp.app i/art﹕ background partial concurrent mark sweep gc freed 106179(3mb) allocspace objects, 60(1196kb) los objects, 24% free, 12mb/16mb, paused 13.157ms total 220.810ms     09-21 12:43:09.363    4425-4440/com.mani.myapp.app w/art﹕ suspending threads took: 29.424ms     09-21 12:43:09.373    4425-4445/com.mani.myapp.app w/art﹕ suspending threads took: 9.951ms     09-21 12:43:09.394    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 93791(2mb) allocspace objects, 46(920kb) los objects, 13% free, 12mb/14mb, paused 20.565ms total 80.242ms     09-21 12:43:09.551    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 48697(1374kb) allocspace objects, 24(480kb) los objects, 12% free, 12mb/14mb, paused 13.081ms total 66.466ms     09-21 12:43:09.847    4425-4440/com.mani.myapp.app w/art﹕ suspending threads took: 13.442ms     09-21 12:43:09.858    4425-4445/com.mani.myapp.app w/art﹕ suspending threads took: 10.652ms     09-21 12:43:09.884    4425-4445/com.mani.myapp.app i/art﹕ background partial concurrent mark sweep gc freed 110673(3mb) allocspace objects, 59(1180kb) los objects, 23% free, 13mb/17mb, paused 23.900ms total 250.072ms     09-21 12:43:10.164    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 100923(2mb) allocspace objects, 49(980kb) los objects, 12% free, 13mb/15mb, paused 13.358ms total 78.789ms     09-21 12:43:10.333    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 50897(1411kb) allocspace objects, 24(480kb) los objects, 11% free, 14mb/15mb, paused 14.194ms total 73.668ms     09-21 12:43:10.688    4425-4445/com.mani.myapp.app i/art﹕ background partial concurrent mark sweep gc freed 123400(3mb) allocspace objects, 64(1280kb) los objects, 21% free, 14mb/18mb, paused 12.810ms total 258.849ms     09-21 12:43:10.990    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 105295(2mb) allocspace objects, 48(960kb) los objects, 11% free, 14mb/16mb, paused 13.258ms total 83.864ms     09-21 12:43:11.165    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 54353(1492kb) allocspace objects, 25(500kb) los objects, 10% free, 15mb/16mb, paused 12.175ms total 75.996ms     09-21 12:43:11.495    4425-4440/com.mani.myapp.app w/art﹕ suspending threads took: 155.495ms     09-21 12:43:11.506    4425-4445/com.mani.myapp.app w/art﹕ suspending threads took: 11.615ms     09-21 12:43:11.529    4425-4445/com.mani.myapp.app i/art﹕ background partial concurrent mark sweep gc freed 63385(1880kb) allocspace objects, 36(720kb) los objects, 20% free, 15mb/19mb, paused 24.605ms total 275.336ms     09-21 12:43:11.824    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 102216(2mb) allocspace objects, 47(940kb) los objects, 11% free, 15mb/17mb, paused 14.111ms total 81.338ms     09-21 12:43:12.000    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 51526(1402kb) allocspace objects, 23(460kb) los objects, 10% free, 15mb/17mb, paused 13.084ms total 74.463ms     09-21 12:43:12.374    4425-4440/com.mani.myapp.app w/art﹕ suspending threads took: 33.642ms     09-21 12:43:12.387    4425-4445/com.mani.myapp.app w/art﹕ suspending threads took: 13.049ms     09-21 12:43:12.415    4425-4445/com.mani.myapp.app i/art﹕ background partial concurrent mark sweep gc freed 132547(3mb) allocspace objects, 61(1220kb) los objects, 19% free, 16mb/20mb, paused 25.429ms total 318.358ms     09-21 12:43:12.722    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 107327(2mb) allocspace objects, 48(960kb) los objects, 10% free, 16mb/18mb, paused 15.514ms total 87.307ms     09-21 12:43:12.878    4425-4440/com.mani.myapp.app w/art﹕ suspending threads took: 36.380ms     09-21 12:43:12.891    4425-4445/com.mani.myapp.app w/art﹕ suspending threads took: 13.041ms     09-21 12:43:12.912    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 39227(1141kb) allocspace objects, 20(420kb) los objects, 10% free, 17mb/18mb, paused 26.421ms total 84.216ms     09-21 12:43:13.312    4425-4445/com.mani.myapp.app i/art﹕ background partial concurrent mark sweep gc freed 143804(3mb) allocspace objects, 62(1480kb) los objects, 18% free, 17mb/21mb, paused 15.782ms total 309.543ms     09-21 12:43:13.622    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 103652(2mb) allocspace objects, 43(1032kb) los objects, 9% free, 18mb/20mb, paused 13.240ms total 89.262ms     09-21 12:43:13.809    4425-4445/com.mani.myapp.app i/art﹕ background sticky concurrent mark sweep gc freed 53375(1495kb) allocspace objects, 22(528kb) los objects, 8% free, 18mb/20mb, paused 15.340ms total 83.655ms     09-21 12:43:14.241    4425-4445/com.mani.myapp.app i/art﹕ background partial concurrent mark sweep      09-21 12:34:09.987  28979-28994/com.mani.myapp.app w/art﹕ suspending threads took: 3.798s     09-21 12:34:10.175  28979-28999/com.mani.myapp.app w/art﹕ suspending threads took: 188.530ms     09-21 12:34:10.418  28979-28999/com.mani.myapp.app i/art﹕ clamp target gc heap 259mb 256mb     09-21 12:34:10.418  28979-28999/com.mani.myapp.app i/art﹕ background partial concurrent mark sweep gc freed 47(161kb) allocspace objects, 2(160kb) los objects, 0% free, 255mb/256mb, paused 237.084ms total 4.043s     09-21 12:34:10.419  28979-28979/com.mani.myapp.app i/art﹕ waitforgctocomplete 

you have many complex object in customobject. such customobjectqueue, downloadstatuslistener , on. guess reason of crashed. remove complex object customobject. hope can you.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -