android - AsyncTask creation causes crash -


having issues custom class extends asynctask. app targeting android 4.0.3 , below code works fine 30+ people testing it. there 2 users seeing app crash when call new asyncrequest below.

i've got working logger recording text file on users storage , doesn't record entry in asyncrequest constructor. have assume crash happening before constructor called.

one of 2 devices experiencing crash running android 4.0.4 apparently. not sure other device running. unfortunately dont' have access 2 devices can't see logcat output.

any input why object creation causing crash appreciated.

string url = "www.google.com";  new asyncrequest(callback, context).executeonexecutor(asynctask.thread_pool_executor, url); 

and here full asyncrequest class

public class asyncrequest extends asynctask<string, string, string>{  httpurlconnection connection; inputstream instream; iapicallback callback; context context_;  public asyncrequest(iapicallback callback, context context) {     // log entry added testing. never gets called.     filelogger.getfilelogger(context).reportinfo("enter asyncrequest constructor");     this.callback = callback;     context_ = context; }  @override protected string doinbackground(string... uri) {      try {         url url = new url(uri[0] + "?format=json");         filelogger.getfilelogger(context_).reportinfo("async request: sending http " + url);          connection = (httpurlconnection) url.openconnection();         connection.setconnecttimeout(5000);         connection.setreadtimeout(5000);         connection.addrequestproperty("accept-encoding", "gzip");         connection.addrequestproperty("cache-control", "no-cache");          connection.connect();          string encoding = connection.getcontentencoding();          // determine if stream compressed , uncompress if needed.         if (encoding != null && encoding.equalsignorecase("gzip")) {             instream = new gzipinputstream(connection.getinputstream());          }  else {             instream = connection.getinputstream();         }          if (instream != null) {             // process response             bufferedreader br = new bufferedreader(new inputstreamreader(instream));             stringbuilder sb = new stringbuilder();             string line;             while ((line = br.readline()) != null) {                 sb.append(line);             }              return sb.tostring();            }      } catch (sockettimeoutexception e) {         filelogger.getfilelogger(context_).reportexception("async request: sockettimeoutexception", e);         log.i("asyncrequest", "socket timeout occured");     } catch (malformedurlexception e) {         filelogger.getfilelogger(context_).reportexception("async request: malformedurlexception", e);     } catch (ioexception e) {         filelogger.getfilelogger(context_).reportexception("async request: ioexception", e);         log.i("doinbackground:","ioexception");          if (e != null && e.getmessage() != null) {             log.i("doinbackground:",e.getmessage());         }     } catch (exception e) {         filelogger.getfilelogger(context_).reportexception("async request: exception", e);      } {         if (connection != null)             connection.disconnect();     }      return null; }  @override protected void onpostexecute(string result) {      if (result != null)          filelogger.getfilelogger(context_).reportinfo("async request: response valid");     else         filelogger.getfilelogger(context_).reportinfo("async request: invalid response");      callback.execute(result); } } 

edit: per comments below.

here full method call custom asynctask from. logging messages have creating asynctask showing in log. none of exceptions are.

the logging displays url value before creating asyncrequest , url not malformed @ all. it's i'm expecting.

public void getserverinfoasync(iapicallback callback, context context) throws illegalargumentexception, exception {      if (callback == null)         throw new illegalargumentexception("callback");      if (context == null)         throw new illegalargumentexception("context");      try {         filelogger.getfilelogger(context).reportinfo("build url");         string url = getapiurl("system/info");         filelogger.getfilelogger(context).reportinfo("finished building url");          if (url != null) {             filelogger.getfilelogger(context).reportinfo("getserverinfoasync: url " + url);             new asyncrequest(callback, context).executeonexecutor(asynctask.thread_pool_executor, url);         } else {             filelogger.getfilelogger(context).reporterror("getserverinfoasync: url null");         }      } catch (illegalargumentexception iae) {         filelogger.getfilelogger(context).reportexception("getserverinfoasync: illegalargumentexception", iae);         throw iae;     } catch (exception e) {         filelogger.getfilelogger(context).reportexception("getserverinfoasync: exception", e);         throw e;     } } 

first of all, keep in mind executeonexecutor() not available prior api 11. have said issue 4.0.4 device, keep in mind.

here steps take in order troubleshoot problem is. seems if have done few of these reportinfo() statements.

first, assume call getserverinfoasync within try...catch, correct? checking because of use of throw. also, have added logging check errors url. since errors occur before use it, error cannot url, or internet permissions. call asynctask generation references callback , context. have added logging via reportinfo() references context, , work, yes? therefore, context not issue. however, never check callback is. throw error if null, never before call asyncrequest. try reportinfo(callback.tostring()) see is.

if else fails, seem error threading. why not try using asynctask, instead of executeonexecutor(). need more 1 background thread?


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -