我面临Android 8.1 OS中带有Signed apk的JobIntentService的问题。在哪里可以正常使用调试版本。尝试了很多事情,但无法获得解决方案。这是我从Crashalytics获得的崩溃日志。
java.lang.RuntimeException: Unable to stop service com.app.xmpp.XmppService@241c51c6: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.app.JobIntentService$WorkEnqueuer.serviceProcessingFinished()' on a null object reference
at android.app.ActivityThread.handleStopService(ActivityThread.java:3284)
at android.app.ActivityThread.access$2300(ActivityThread.java:188)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1633)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:210)
at android.app.ActivityThread.main(ActivityThread.java:5839)
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:1113)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:879)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.app.JobIntentService$WorkEnqueuer.serviceProcessingFinished()' on a null object reference
at android.support.v4.app.JobIntentService.onDestroy(JobIntentService.java:479)
at com.app.xmpp.XmppService.onDestroy(XmppService.java:91)
at android.app.ActivityThread.handleStopService(ActivityThread.java:3265)
at android.app.ActivityThread.access$2300(ActivityThread.java:188)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1633)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:210)
at android.app.ActivityThread.main(ActivityThread.java:5839)
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:1113)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:879)
如果有人在JobIntentService中遇到类似问题,请帮帮我。
请注意,处理Nullpointer异常无法解决此问题,因为NPE发生在Android Framework的JobIntentService中,我们无法对其进行修改,并且尤其是在Signed APK中发生。
XMPP Service OnDestroy
@Override
public void onDestroy() {
super.onDestroy();
MyXMPP.instance=null;
MyXMPP.instanceCreated=false;
MyXMPP.connection.disconnect();
xmppConnectionCheckHandler.removeCallbacks(xmppConnectionCheckRunnable);
System.out.println("--------------Xmpp Service Stopped-----------");
}
谢谢。
答案 0 :(得分:0)
来自JobIntentService
类:
@Override
public void onDestroy() {
super.onDestroy();
if (mCompatQueue != null) {
synchronized (mCompatQueue) {
mDestroyed = true;
mCompatWorkEnqueuer.serviceProcessingFinished(); //line 479
}
}
}
@Override
public void onCreate() {
super.onCreate();
if (DEBUG) Log.d(TAG, "CREATING: " + this);
if (Build.VERSION.SDK_INT >= 26) {
mJobImpl = new JobServiceEngineImpl(this);
mCompatWorkEnqueuer = null;
} else {
mJobImpl = null;
ComponentName cn = new ComponentName(this, this.getClass());
mCompatWorkEnqueuer = getWorkEnqueuer(this, cn, false, 0);
}
}
您对子类中的mCompatWorkEnqueuer
或mCompatQueue
执行任何操作吗?是说要像将其设置为null
或super.onCreate()
调用吗?
请注意,第479行的执行取决于mCompatQueue
值的存在。此外,对于API的26(8.0)及更高版本,mCompatWorkEnqueuer
中的null
设置为onCreate