gpt4 book ai didi

android - 有时 Intent 服务在 Response Receiver 中再次启动服务时崩溃

转载 作者:搜寻专家 更新时间:2023-11-01 08:31:20 24 4
gpt4 key购买 nike

有时我在 onReceive() 方法上再次重启它时遇到我的 Intent 服务崩溃的问题。这是我的堆栈跟踪。

"java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.ComponentName android.content.Intent.getComponent()' on a null object reference at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1207) at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1238) at android.app.ContextImpl.startService(ContextImpl.java:1222) at android.content.ContextWrapper.startService(ContextWrapper.java:581) at com.live.wheelz.MapFragmentPassenger$ResponseReceiver$3.run(MapFragmentPassenger.java:3162) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) " Here is my 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 is arrived at your location");
// snack("Driver is arrived at your 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);
for (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");
}

}


}

最佳答案

我在调试 startService(servicedriver) 后解决了它; servicedriver object is null 我重新启动它,如果它是 null like

if(servicedriver!=null) {
startService(servicedriver);
}
else{
startservice();
}

这里是启动服务

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);
}
}

关于android - 有时 Intent 服务在 Response Receiver 中再次启动服务时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40483130/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com