android - Some time Intent service crash on start service again in Response Reciver -
sometime facing issue intent service crash while restart again on onreceive() method. here stack trace.
"java.lang.nullpointerexception: attempt invoke virtual method 'android.content.componentname android.content.intent.getcomponent()' on null object reference @ android.app.contextimpl.validateserviceintent(contextimpl.java:1207) @ android.app.contextimpl.startservicecommon(contextimpl.java:1238) @ android.app.contextimpl.startservice(contextimpl.java:1222) @ android.content.contextwrapper.startservice(contextwrapper.java:581) @ com.live.wheelz.mapfragmentpassenger$responsereceiver$3.run(mapfragmentpassenger.java:3162) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:148) @ android.app.activitythread.main(activitythread.java:5417) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:726) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:616) " here code
public class responsereceiver extends wakefulbroadcastreceiver { public static final string action_resp = "com.live.responsereceiver.intent.action.message_processed"; @override public void onreceive(context context, intent intent) { if(!intent.getstringextra("journeystate").equals("jr_droped") && !intent.getstringextra("journeystate").equals("jr_canceled") ) { if(intent.getstringextra("journeystate").equals("jr_arrived") && alertcounter==0) { alertcounter=alertcounter+1; popup.dismisdialog(); soundalert.initrigtone("driver arrived @ location"); // snack("driver arrived @ location","message","long"); } if (shareddata.getissimulation() == true) { if (intent.getbooleanextra("same", true) == false) { double latc = intent.getdoubleextra("pdriverlatitude", 0.0); double lonc = intent.getdoubleextra("pdriverlongitude", 0.0); //dname.settext("latitude:"+lat+"longitude:"+lon); if (driver != null) { driver.remove(); } //string address=getaddress(latpickup,lonpickup); (marker oc : nearest_driver) { oc.remove(); } driver = googlemap.addmarker(new markeroptions() .position(new latlng(latc, lonc)) .title("current location driver").icon(bitmapdescriptorfactory.fromresource(r.drawable.bike_left)) .draggable(true)); if (markerlocation != null) { markerlocation.remove(); } markerlocation = googlemap.addmarker(new markeroptions() .position(new latlng(shareddata.getnewlat(), shareddata.getnewlon())) .title("passenger current location").icon(bitmapdescriptorfactory.fromresource(r.drawable.bluedot))); if (shareddata.getisrating() == false) { handler handler = new handler(); handler.postdelayed(new runnable() { @override public void run() { try { startservice(servicedriver); } catch (exception ex) { system.out.print(""); } } }, shareddata.getpassenger_request_delay_time()); } } if (intent.getbooleanextra("same", false) == true) { if (markerlocation != null) { markerlocation.remove(); } markerlocation = googlemap.addmarker(new markeroptions() .position(new latlng(shareddata.getnewlat(), shareddata.getnewlon())) .title("passenger current location").icon(bitmapdescriptorfactory.fromresource(r.drawable.bluedot))); if (shareddata.getisrating() == false) { if (receiver != null) { handler handler = new handler(); handler.postdelayed(new runnable() { @override public void run() { try { startservice(servicedriver); } catch (exception ex) { system.out.print(""); } //startservice(servicedriver); } }, shareddata.getpassenger_request_delay_time()); } } } } if (shareddata.getissimulation() == false) { if (intent.getbooleanextra("same", false) == false) { if (intent.getbooleanextra("connection_error", false) == false) { latc = intent.getdoubleextra("pdriverlatitude", 0.0); lonc = intent.getdoubleextra("pdriverlongitude", 0.0); //snack("driver current lat:"+latc+" driver current lon:"+lonc, "message", " "); //ali abbas location diffrnce calc double latdrvr = shareddata.getpickuplocationlat(); double londrvr = shareddata.getpickuplocationlon(); double distancediff = getdistanceinmiles(latc,lonc,latdrvr,londrvr); double getdisrnce = sharedata.getdrvrpsngrrnge() ; if(distancediff <= sharedata.getdrvrpsngrrnge() && intent.getstringextra("journeystate").equals("jr_driveraccepted")) { /*if (!ispopuped) { ispopuped =true ;*/ fncdrvrarndpsngr(); //} }else if(distancediff > sharedata.getdrvrpsngrrnge() && intent.getstringextra("journeystate").equals("jr_driveraccepted")){ fncdrvrarndpsngrpopupdismiss(); } //ali abbas distance calc ends } smoothly(latc, lonc); if (shareddata.getisrating() == false) { if (intent.getbooleanextra("connection_error", true) == true) { snack("internet connection error", "message", " "); fncdrvrarndpsngrpopupdismiss(); } else { appasyntaskaddress setaddress = new appasyntaskaddress(mapfragmentpassenger.this, latc, lonc, "driverlocation", false); setaddress.execute(); //snack("driver arrived at:"+pickuplocationtext.gettext().tostring(), "message", " "); } if (receiver != null) { handler handler = new handler(); handler.postdelayed(new runnable() { @override public void run() { try { startservice(servicedriver); } catch (exception ex) { system.out.print(""); } //startservice(servicedriver); } }, shareddata.getpassenger_request_delay_time());//shareddata.getpassenger_request_delay_time() } } else { googlemap.clear(); } } if (intent.getbooleanextra("same", true) == true) { if (shareddata.getisrating() == false) { //snack("same lat lon", "message", " "); if (receiver != null) { handler handler = new handler(); handler.postdelayed(new runnable() { @override public void run() { try { startservice(servicedriver); } catch (exception ex) { system.out.print(""); } // startservice(servicedriver); } }, shareddata.getpassenger_request_delay_time());//shareddata.getpassenger_request_delay_time() } } else { googlemap.clear(); } } } } if(intent.getstringextra("journeystate").equals("jr_droped")) { if(!sharedata.isonratingscreen()) { intent intsetpass = new intent(mapfragmentpassenger.this, ratingscreenpassenger.class); intsetpass.setflags(intent.flag_activity_clear_top); startactivity(intsetpass); } } if(intent.getstringextra("journeystate").equals("jr_canceled")) { sharedata.setjmode(false); sharedata.setisrating(true); //db.deletebillingparameter(); db.deletejourneyrating(sharedata.getdriver_rquested_journeyid(), "p"); changebutton(); snack("journey canceled","message","long"); soundalert.initrigtone("journey canceled"); } } }
i solve after doing debugging startservice(servicedriver); servicedriver object null start again if null like
if(servicedriver!=null) { startservice(servicedriver); } else{ startservice(); }
here start service
public void startservice() { if (shareddata.getissimulation() == true) { jmode = true; shareddata.setisrating(false); servicedriver = new intent(this, locationservice.class); this.startservice(servicedriver); shareddata.setjmode(true); } if (shareddata.getissimulation() == false) { jmode = true; shareddata.setisrating(false); servicedriver = new intent(this, locationservicedriver.class); this.startservice(servicedriver); shareddata.setjmode(true); } }
Comments
Post a Comment