- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在两者上都使用 Marshmallow,所以我不明白为什么我的应用程序在模拟器上稳定,但在手机上却不稳定。它可以工作,但很快就会崩溃。这是日志猫:
Process: com.madhatter.nat.test, PID: 28210
java.lang.RuntimeException: Unable to start service com.madhatter.nat.test.OverlayService@89014f1 with null: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Bundle android.content.Intent.getExtras()' on a null object reference
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3045)
at android.app.ActivityThread.-wrap17(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1452)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Bundle android.content.Intent.getExtras()' on a null object reference
at com.madhatter.nat.test.OverlayService.onStartCommand(OverlayService.java:45)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3028)
at android.app.ActivityThread.-wrap17(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1452)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
以及OverlayService中的onStartCommand:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
item = intent.getExtras().getParcelable(DataItemAdapter.ITEM_KEY);
if (item == null) {
throw new AssertionError("Null data item received!");
} else {
getImageDrawable();
}
return START_STICKY;
}
第 45 行是以“item”开头的行。我将非常感谢您的一些指点。如果需要,我可以发布更多代码。谢谢!
编辑:Logcat 使用 START__REDELIVER_INTENT
01-10 09:18:09.144 1840-7536/? I/WindowState: WIN DEATH: Window{6594f29 u0 com.madhatter.nat.test/com.madhatter.nat.test.MainActivity}
01-10 09:18:09.147 1840-7538/? I/WindowState: WIN DEATH: Window{cee56ff u0 com.madhatter.nat.test}
01-10 09:18:09.151 1840-6620/? I/WindowState: WIN DEATH: Window{26fc259 u0 com.madhatter.nat.test}
01-10 09:18:09.154 1840-7539/? I/ActivityManager: Process com.madhatter.nat.test (pid 29128) has died
01-10 09:18:09.154 1840-7539/? W/ActivityManager: Scheduling restart of crashed service com.madhatter.nat.test/.OverlayService in 32668ms
01-10 09:18:09.157 1840-3383/? W/InputDispatcher: channel '7370c7b com.madhatter.nat.test/com.madhatter.nat.test.SelectionPage (server)' ~ Consumer closed input channel or an error occurred. events=0x9
01-10 09:18:09.157 1840-3383/? E/InputDispatcher: channel '7370c7b com.madhatter.nat.test/com.madhatter.nat.test.SelectionPage (server)' ~ Channel is unrecoverably broken and will be disposed!
01-10 09:18:09.157 1840-3383/? W/InputDispatcher: channel 'dc69e50 com.madhatter.nat.test/com.madhatter.nat.test.LauncherPage (server)' ~ Consumer closed input channel or an error occurred. events=0x9
01-10 09:18:09.157 1840-3383/? E/InputDispatcher: channel 'dc69e50 com.madhatter.nat.test/com.madhatter.nat.test.LauncherPage (server)' ~ Channel is unrecoverably broken and will be disposed!
01-10 09:18:09.159 1840-4579/? I/WindowState: WIN DEATH: Window{dc69e50 u0 com.madhatter.nat.test/com.madhatter.nat.test.LauncherPage}
01-10 09:18:09.159 1840-4579/? W/InputDispatcher: Attempted to unregister already unregistered input channel 'dc69e50 com.madhatter.nat.test/com.madhatter.nat.test.LauncherPage (server)'
01-10 09:18:09.162 1840-1851/? I/WindowState: WIN DEATH: Window{7370c7b u0 com.madhatter.nat.test/com.madhatter.nat.test.SelectionPage}
01-10 09:18:09.162 1840-1851/? W/InputDispatcher: Attempted to unregister already unregistered input channel '7370c7b com.madhatter.nat.test/com.madhatter.nat.test.SelectionPage (server)'
01-10 09:18:41.843 1840-1854/? I/ActivityManager: Start proc 32159:com.madhatter.nat.test/u0a125 for service com.madhatter.nat.test/.OverlayService
01-10 09:18:41.906 32159-32159/? W/System: ClassLoader referenced unknown path: /data/app/com.madhatter.nat.test-2/lib/arm
最佳答案
查看 Service 的文档。以下是当您从 onStartCommand()
返回 START_STICKY
时发生的情况:
if this service's process is killed while it is started (after returning from onStartCommand(Intent, int, int)), then leave it in the started state but don't retain this delivered intent. Later the system will try to re-create the service. Because it is in the started state, it will guarantee to call onStartCommand(Intent, int, int) after creating the new service instance; if there are not any pending start commands to be delivered to the service, it will be called with a null intent object, so you must take care to check for this.
这正是您的情况所发生的情况,您的 intent
参数得到一个 null
。您应该检查 null
,或者返回 START_REDELIVER_INTENT
,其行为如下:
if this service's process is killed while it is started (after returning from onStartCommand(Intent, int, int)), then it will be scheduled for a restart and the last delivered Intent re-delivered to it again via onStartCommand(Intent, int, int).
关于java - 应用程序在模拟器上运行良好,但在手机上经常崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41553311/
嗨,我正在考虑开发一种文件传输程序,想知道我是否想要尽可能好的加密,我应该使用什么? 我会用 C# 开发它,所以我可以访问 .net 库 :P在我的 usb 上有一个证书来访问服务器是没有问题的,如果
我创建的这个计算两个数组的交集是线性的方法的复杂度(在良好、平均、最差的情况下)? O(n) public void getInt(int[] a,int[] b){ int i=0; int
我已经能够使用 RTCPeerConnection.getStats() API 获得 WebRTC 音频调用的各种统计信息(抖动、RTT、丢包等)。 我需要将整体通话质量评为优秀、良好、一般或差。
基本问题: 如果我正在讲述/修改数据,我应该通过索引硬编码索引访问文件的元素,即 targetFile.getElement(5);通过硬编码标识符(内部翻译成索引),即 target.getElem
在 Linux 上,我想知道要调用什么“C”API 来获取每个 CPU 的统计信息。 我知道并且可以从我的应用程序中读取 /proc/loadavg,但这是系统范围的负载平均值,而不是每个 CPU 的
在客户端浏览器中使用 fetch api,GET 或 POST 没有问题,但 fetch 和 DELETE 有问题。它似乎将 DELETE 请求方法更改为 OPTIONS。 大多数研究表明是一个cor
我是一名优秀的程序员,十分优秀!