crash - android volley crashes without internet connection -
i ve got problem. took me while figure out volley or better, finish app crashes when tries send info no connection (2g/3g/lte,wifi). can happen if smartphone in flight mode or got no net connection.
here source code:
public class appcontroller extends application { public static final string tag = appcontroller.class .getsimplename(); private requestqueue mrequestqueue; private imageloader mimageloader; private static appcontroller minstance; @override public void oncreate() { super.oncreate(); minstance = this; } public static synchronized appcontroller getinstance() { homecoming minstance; } public requestqueue getrequestqueue() { if (mrequestqueue == null) { mrequestqueue = volley.newrequestqueue(getapplicationcontext()); } homecoming mrequestqueue; } public imageloader getimageloader() { getrequestqueue(); if (mimageloader == null) { mimageloader = new imageloader(this.mrequestqueue, new lrubitmapcache()); } homecoming this.mimageloader; } public <t> void addtorequestqueue(request<t> req, string tag) { // set default tag if tag empty req.settag(textutils.isempty(tag) ? tag : tag); getrequestqueue().add(req); } public <t> void addtorequestqueue(request<t> req) { req.settag(tag); getrequestqueue().add(req); } public void cancelpendingrequests(object tag) { if (mrequestqueue != null) { mrequestqueue.cancelall(tag); } } public void addtorequestqueue(jsonobjectrequest jsonobjreq, string tag_json_obj) { // todo auto-generated method stub getrequestqueue().add(jsonobjreq); }
}
this how requests looks within app. going send jsonobject.
public static void sendsms(jsonobject obj) { // tag used cancel request string tag_json_obj = "json_obj_req"; string url = "http:/<ip>/<file>.php"; jsonobjectrequest objreq = new jsonobjectrequest(method.post, url, obj, new response.listener<jsonobject>() { @override public void onresponse(jsonobject response) { log.d(tag, response.tostring()); } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { volleylog.d(tag, "error: " + error.getmessage()); // hide progress dialog } }); // adding request request queue appcontroller.getinstance().addtorequestqueue(objreq, tag_json_obj); }
if smartphone gots net connection (2g/3g/lte,wifi), working fine. if in flight mode error:
can please help me handle this? tryed "try" , "catch" blocks isn´t working me. can volley manage without crashing app? in advance! :)
i think throwing npe becuase of line:
volleylog.d(tag, "error: " + error.getmessage());
the "error" object might null.
android crash try-catch send android-volley
No comments:
Post a Comment