Android outofmemoryerror while fetching json -


i trying fetch data json size 400kb interesting when trying data json error:

07-13 19:09:59.311: e/art(2854): throwing outofmemoryerror "failed allocate 966540 byte allocation 777308 free bytes , 759kb until oom" 07-13 19:09:59.316: e/androidruntime(2854): fatal exception: thread-206 07-13 19:09:59.316: e/androidruntime(2854): process: com.wunderlist.slidinglayersample, pid: 2854 07-13 19:09:59.316: e/androidruntime(2854): java.lang.outofmemoryerror: failed allocate 966540 byte allocation 777308 free bytes , 759kb until oom 07-13 19:09:59.316: e/androidruntime(2854):     @ java.lang.abstractstringbuilder.enlargebuffer(abstractstringbuilder.java:95) 07-13 19:09:59.316: e/androidruntime(2854):     @ java.lang.abstractstringbuilder.append0(abstractstringbuilder.java:163) 07-13 19:09:59.316: e/androidruntime(2854):     @ java.lang.stringbuilder.append(stringbuilder.java:311) 07-13 19:09:59.316: e/androidruntime(2854):     @ org.json.jsontokener.nextstring(jsontokener.java:224) 07-13 19:09:59.316: e/androidruntime(2854):     @ org.json.jsontokener.nextvalue(jsontokener.java:107) 07-13 19:09:59.316: e/androidruntime(2854):     @ org.json.jsontokener.readobject(jsontokener.java:385) 07-13 19:09:59.316: e/androidruntime(2854):     @ org.json.jsontokener.nextvalue(jsontokener.java:100) 07-13 19:09:59.316: e/androidruntime(2854):     @ org.json.jsontokener.readarray(jsontokener.java:430) 07-13 19:09:59.316: e/androidruntime(2854):     @ org.json.jsontokener.nextvalue(jsontokener.java:103) 07-13 19:09:59.316: e/androidruntime(2854):     @ org.json.jsonarray.<init>(jsonarray.java:92) 07-13 19:09:59.316: e/androidruntime(2854):     @ org.json.jsonarray.<init>(jsonarray.java:108) 07-13 19:09:59.316: e/androidruntime(2854):     @ com.android.volley.toolbox.jsonarrayrequest.parsenetworkresponse(jsonarrayrequest.java:50) 07-13 19:09:59.316: e/androidruntime(2854):     @ com.android.volley.networkdispatcher.run(networkdispatcher.java:121) 

the main idea when press button 10 strings json code happens in onclick() method:

private void makejsonarrayrequest() {      //showpdialog();      jsonarrayrequest req  = new jsonarrayrequest(urljsonarry,new response.listener<jsonarray>() {         @override         public void onresponse(jsonarray response) {              log.d(tag, response.tostring());              try {                 // parsing json array response                 // loop through each json object                 jsonresponse = "";                 (int = 1; < 2; i++) {                      //response.length()                     jsonobject person = (jsonobject) response                             .get(i);                      string name = person.getstring("nosaukums");                     string email = person.getstring("email");                       jsonobject phone = person.getjsonobject("phone");                     string home = phone.getstring("latco");                     string mobile = phone.getstring("longco");                      jsonresponse += "name: " + name + "\n\n";                      jsonresponse += "email: " + email + "\n\n";                             jsonresponse += "home: " + home + "\n\n";                             jsonresponse += "mobile: " + mobile + "\n\n\n";                  }                    txtresponse.settext(jsonresponse);              } catch (jsonexception e) {                 e.printstacktrace();                 toast.maketext(getapplicationcontext(),                         "error: " + e.getmessage(),                         toast.length_long).show();             }              // hidepdialog();         }     }, new response.errorlistener() {         @override         public void onerrorresponse(volleyerror error) {             volleylog.d(tag, "error: " + error.getmessage());             toast.maketext(getapplicationcontext(),                     error.getmessage(), toast.length_short).show();             // hidepdialog();         }     });      // adding request request queue     appcontroller.getinstance().addtorequestqueue(req); } 

do have suggestion or recommendations how solve problem have because have tried many things nothing works

update.

the jsonarray:

[     {     "name" : "ravi tamada",      "email" : "ravi8x@gmail.com",     "phone" : {         "home" : "08947 000000",         "mobile" : "9999999999"     }     },     {     "name" : "tommy",      "email" : "tommy@gmail.com",     "phone" : {         "home" : "08946 000000",         "mobile" : "0000000000"     }     } ] 

try adding android:largeheap="true" manifest file.

    <application     android:allowbackup="true"     android:label="@string/app_name"     android:largeheap="true" > 

or use jackson json library.

hope may :)


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -