gpt4 book ai didi

java - 关闭应用程序后获取 NullPointerException - android

转载 作者:行者123 更新时间:2023-11-29 04:58:58 25 4
gpt4 key购买 nike

我在关闭(并从我设备上最近的应用程序中删除)我的应用程序后收到此错误,它每次都会发生。

09-22 23:44:28.503    4021-4021/? I/art﹕ Late-enabling -Xcheck:jni
09-22 23:44:28.584 4021-4021/cz.united121.android.revizori D/cz.united121.android.revizori.App﹕ onCreate
09-22 23:44:28.642 4021-4021/cz.united121.android.revizori D/cz.united121.android.revizori.service.MyUpdatingService﹕ onCreate
09-22 23:44:28.677 4021-4021/cz.united121.android.revizori D/AndroidRuntime﹕ Shutting down VM
09-22 23:44:28.679 4021-4021/cz.united121.android.revizori E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: cz.united121.android.revizori, PID: 4021
java.lang.RuntimeException: Unable to start service cz.united121.android.revizori.service.MyUpdatingService@3a7bf84e with null: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getAction()' on a null object reference
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2913)
at android.app.ActivityThread.access$2100(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1390)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5312)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getAction()' on a null object reference
at cz.united121.android.revizori.service.MyUpdatingService.onStartCommand(MyUpdatingService.java:94)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2896)
            at android.app.ActivityThread.access$2100(ActivityThread.java:148)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1390)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5312)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)

异常引用的行 (Log.d(TAG, "onStartCommand"+ intent.getAction());) 在 onStartCommand 的服务中:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
Log.d(TAG, "onStartCommand" + intent.getAction());
if (intent.getAction().equals(SERVICE_FORCE)) {
LOCATION_APROVAL = true;
if (mLastKnownPosition != null) {
mTimeAproving.run();
}
} else if (intent.getAction().equals(SERVICE_START)) {
mUpdatingTimer.scheduleAtFixedRate(mTimeAproving, 0, PERIOD_BETWEEN_UPDATING);
} else if (intent.getAction().equals(SERVICE_STOP)) {
LOCATION_APROVAL = false;
mLastKnownPosition = null;
mUpdatingTimer.cancel();
mUpdatingTimer.purge();
}
return START_STICKY;
}

提前谢谢你。

最佳答案

您的应用和服务被终止,然后服务在您使用 START_STICKY 标志时重新启动。在这种情况下,传递给 onStartCommand()intent 将为空。参见 Reasons that the passed Intent would be NULL in onStartCommand

根据您的逻辑,您可以考虑返回 START_REDELIVER_INTENT

关于java - 关闭应用程序后获取 NullPointerException - android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32731782/

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