【发布时间】:2011-05-24 13:40:26
【问题描述】:
得到如下代码:
// This is com.n.common.Networking.downloadBmp( ) function
// ...
byte[] data = inputStreamToByteArray(new PatchedInputStream(connectJava(url)));
// if the data is null in this moment - return;
if (data == null) // <--- line 185
return null;
// ...
得到了这样的异常:
ERROR/AndroidRuntime(4526): Uncaught handler: thread pool-1-thread-2 exiting due to uncaught exception
ERROR/AndroidRuntime(4526): java.lang.NullPointerException
ERROR/AndroidRuntime(4526): at com.n.common.Networking.downloadBmp(Networking.java:185)
ERROR/AndroidRuntime(4526): at com.n.common.AsyncNetworking$3.run(AsyncNetworking.java:203)
ERROR/AndroidRuntime(4526): at java.lang.Thread.run(Thread.java:1060)
ERROR/AndroidRuntime(4526): at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:648)
ERROR/AndroidRuntime(4526): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:673)
ERROR/AndroidRuntime(4526): at java.lang.Thread.run(Thread.java:1060)
这怎么可能?
编辑:这可能是由于使用了 Eclipse“组织导入”功能,该功能改变了行号 - 并将较新的代码版本与旧部署的代码版本进行比较。感谢大家的帮助。
【问题讨论】:
-
必须在
if (data == null)检查之外。 -
Networking.java第 185 行是什么? -
是来自 Networking.java 的代码吗?
-
不,不是。我应该张贴截图来证明吗? :) @Nanne:我的班级,你在上面看到的片段。
-
@Kocus,
NullPointerException可能被PatchedInputStream构造函数、connectJava方法或inputStreamToByteArray抛出。我建议您查阅他们各自的文档。
标签: java android nullpointerexception