java - NullPointerException in AsyncTask onPostExecute on line 1 -


i have application uses bugsense. i'm getting reports of nullpointerexception crashes bugsense in onpostexecute method of asynctask. strange thing report says nullpointer exception happens on com.xxxxxx.xxxxx.projectname.initrequest.onpostexecute(:1) . , unfortunatelly cannot reproduce error.

java.lang.nullpointerexception @ com.xxxx.xxxx.initrequest.onpostexecute(:1) @ android.os.asynctask.finish(asynctask.java:417) @ android.os.asynctask.access$300(asynctask.java:127) @ android.os.asynctask$internalhandler.handlemessage(asynctask.java:429) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:130) @ android.app.activitythread.main(activitythread.java:3687) @ java.lang.reflect.method.invokenative(method.java) @ java.lang.reflect.method.invoke(method.java:507) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:867) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:625) @ dalvik.system.nativestart.main(nativestart.java) 

and here code asynctask

class initrequest extends asynctask<void, void, pair<hashmap<string,object>,exception>>{  private authtoken authtoken; private int amount; private initcallback pic; private mode mode; public boolean st = false; public initrequest(authtoken authtoken, int amount,initcallback pic, mode mode){     this.authtoken = authtoken;     this.amount = amount;     this.pic = pic;     this.mode = mode; } @override protected void onpreexecute(){     super.onpreexecute();     this.st = true; }  @override protected pair<hashmap<string,object>,exception> doinbackground(void... params){      try{         pair<exception,string> inputstreamorexception = null;         if (this.mode.equals(develop)){             inputstreamorexception  = utilities.getcorrectinputstream(                         utilities.buildurl(xxxx));         }else {             inputstreamorexception  = utilities.getcorrectinputstream(                     utilities.buildurl("zzzzz));         }         if (inputstreamorexception.second == null){             return new pair<hashmap<string,object>,exception>(null,inputstreamorexception.first);         }         hashmap<string,object> returnmap = paypalinitparser.parse(inputstreamorexception.second);         return new pair<hashmap<string,object>,exception>(returnmap,null);     }catch (malformedurlexception murle){         murle.printstacktrace();     }catch (parserconfigurationexception pce){         pce.printstacktrace();     }catch (saxexception saxe){         saxe.printstacktrace();     }catch (ioexception ioe){         ioe.printstacktrace();     }     return null; } @override protected void oncancelled(pair<hashmap<string,object>,exception> result){      this.st = false; } @override protected void onpostexecute(pair<hashmap<string,object>,exception> result){      if (result == null){         if (helper.context != null){             ((interface)helper.context).failwitherror(new error(" authorization failed","200"));         }         this.st = false;         return;     }     if (result.second == null){         if (result.first != null && result.first.get("error") == null){             credentials pc = (credentials)result.first.get("result");              if (pic!= null){                 pic.initfinished(pc);             }          }else {             if (helper.context != null){                 ((interface)helper.context).failwitherror(new error("authorization failed","200"));             }         }     }else {         if (result.second != null)             result.second.printstacktrace();          if (helper.context != null){             ((interface)helper.context).failwitherror(new error("authorization failed","200"));         }     }     this.st = false; } } 

has encounter same/similar error? thought main thread of activity not exists anymore. in activity lifecycle i'm checking if asynctask running or pending , i'm cancelling in onpause method of calling activity. appreciated. in advance.

since said application doesn't crash if put breakpoint, problem threading. code in asynctask running before other code , creating exception.

i guess in line, credentials pc = (credentials)result.first.get("result"); result object not yet instantiated , exception being thrown.

so make sure objects instantiated before call asynctask. hope helps!


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -