android - Could not allocate JNI Env -
i'm updating api every 2seconds,
receiving error , application closes.
fatal exception: main process: com.application.toweeloasep, pid: 6681 java.lang.outofmemoryerror: not allocate jni env @ java.lang.thread.nativecreate(native method) @ java.lang.thread.start(thread.java:730) @ com.android.volley.requestqueue.start(requestqueue.java:145) @ com.android.volley.toolbox.volley.newrequestqueue(volley.java:66) @ com.android.volley.toolbox.volley.newrequestqueue(volley.java:78) @ com.application.toweeloasep.fragments.jobs$5$1.run(jobs.java:260) @ android.os.handler.handlecallback(handler.java:751) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:154) @ android.app.activitythread.main(activitythread.java:6077) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:865) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:755)
after minute, starts crash , receives error.
overdoing things volley?
private void setrepeatingasynctask() { final handler handler = new handler(); timer timer = new timer(); timertask task = new timertask() { @override public void run() { handler.post(new runnable() { public void run() { try { if (checkrequests) { requestqueue mrequestqueue = volley.newrequestqueue(getactivity()); stringrequest mstringrequest = new stringrequest(request.method.post, "http://api.000.com/booking/track", new response.listener<string>() { @override public void onresponse(string response) { log.e("response:track", response); try { jsonobject json = new jsonobject(response); string mstatus = json.getstring("status"); if (mstatus.equalsignorecase("0")) { log.e("status", mstatus); } else if (mstatus.equalsignorecase("1")) { jsonarray infos = json.getjsonarray("data"); booking_id = infos.getjsonobject(0).getstring("id"); user_address_location = infos.getjsonobject(0).getstring("user_address_location"); mtxtbatteryinfo.settext(infos.getjsonobject(0).getjsonobject("battery").getstring("model")); mtxtuserlocation.settext(user_address_location); checkrequests = false; mjobshome.setvisibility(view.gone); mjobrequest.setvisibility(view.visible); if (!ontick) { mcountdowntimer.start(); ontick = true; } } } catch (exception e) { log.e("err", e.tostring()); } } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { log.e("err", error.tostring()); } }); mrequestqueue.add(mstringrequest); } else { requestqueue requestplaceinfo = volley.newrequestqueue(getactivity()); stringrequest request2 = new stringrequest(request.method.post, "http://api.000.com/booking/track", new response.listener<string>() { @override public void onresponse(string response) { log.e("response", response); } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { toast.maketext(getactivity(), error.tostring(), toast.length_short).show(); } }) { @override protected map<string, string> getparams() throws authfailureerror { map<string, string> params = new hashmap<>(); params.put("booking_id", booking_id); params.put("rider_long", string.valueof(lng)); params.put("rider_lat", string.valueof(lat)); return params; } }; requestplaceinfo.add(request2); } } catch (exception e) { // error, } } }); } }; timer.schedule(task, 0, 2000); // interval of 1 minute }
outofmemoryerror ... @ com.android.volley.toolbox.volley.newrequestqueue
why need create new requestqueue or stringrequest every 2 seconds?
try making 1 of each.
private final response.errorlistener errorlistener = new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { log.e("err", string.valueof(error)); } }; private void setrepeatingvolleytask() { final requestqueue mrequestqueue = volley.newrequestqueue(getactivity()); final stringrequest trackrequest = new stringrequest(request.method.post, "http://api.toweelo.com/booking/track", new response.listener<string>() { @override public void onresponse(string response) { log.d("response:track", response); try { jsonobject json = new jsonobject(response); string mstatus = json.getstring("status"); if (mstatus.equalsignorecase("0")) { log.d("status", mstatus); } else if (mstatus.equalsignorecase("1")) { jsonarray infos = json.getjsonarray("data"); booking_id = infos.getjsonobject(0).getstring("id"); user_address_location = infos.getjsonobject(0).getstring("user_address_location"); mtxtbatteryinfo.settext(infos.getjsonobject(0).getjsonobject("battery").getstring("model")); mtxtuserlocation.settext(user_address_location); checkrequests = false; mjobshome.setvisibility(view.gone); mjobrequest.setvisibility(view.visible); if (!ontick) { mcountdowntimer.start(); ontick = true; } } } catch (exception e) { log.e("err", e.tostring()); } } }, errorlistener ); final stringrequest trackrequest2 = new stringrequest(request.method.post, "http://api.toweelo.com/booking/track", new response.listener<string>() { @override public void onresponse(string response) { log.d("response", response); } }, errorlistener) { @override protected map<string, string> getparams() throws authfailureerror { map<string, string> params = new hashmap<>(); params.put("booking_id", booking_id); params.put("rider_long", string.valueof(lng)); params.put("rider_lat", string.valueof(lat)); return params; } }; timer timer = new timer(); timertask task = new timertask() { @override public void run() { handler.post(new runnable() { public void run() { // trying catch here?? try { if (checkrequests) { mrequestqueue.add(trackrequest); } else { mrequestqueue.add(trackrequest2); } catch ( ... ) { .... }
note: can use jsonobjectrequest
instead of parsing json stringrequest
Comments
Post a Comment