3

got code looking like this:

// 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;
// ...

And got exception like this:

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)

How is that possible?

EDIT: It is probable due to using Eclipse "Organize imports" function, which altered line numbers - and comparing newer code version to the old deployed one. Thx everyone for help.

Kocus
  • 1,613
  • 17
  • 31
  • 1
    Must be outside of the `if (data == null)` check. – trojanfoe May 24 '11 at 13:42
  • 1
    what is `Networking.java` line 185? – Nanne May 24 '11 at 13:45
  • Is that code from Networking.java? – Kaj May 24 '11 at 13:45
  • Nope, it is not. Should I post screenshot to prove it? :) @Nanne: my class, fragment of which you are seeing above. – Kocus May 24 '11 at 13:46
  • @Kocus, the `NullPointerException` is probably being thrown by either the `PatchedInputStream` constructor, the `connectJava` method, or the `inputStreamToByteArray`. I'd suggest you consult their respective documentation. – mre May 24 '11 at 13:47
  • Look for the "caused by" line in your log, you should get the linenumber there. – Nanne May 24 '11 at 14:01

3 Answers3

2

Something else is going on, that line can not produce a NPE. Most likely you have a stale build that is reporting the wrong line number in the logs.

Andrew White
  • 52,720
  • 19
  • 113
  • 137
2

Should be a deployment problem or something related to saving files and having multiple versions. The code that throws the Exception has to have a different line 185 than what you have posted.

Try clean / recompile / (redeploy) and see if the line number changes

b.buchhold
  • 3,837
  • 2
  • 24
  • 33
  • Problem is that I cannot reproduce this exception. It just happen in the normal application usage. – Kocus May 24 '11 at 13:50
  • A common 'deployment problem' is a compile error, which leads to android running an old version. Happens to me a lot anyway. – beetstra May 24 '11 at 13:52
  • Ok, I've got it. It is propable due to using Eclipse "Organize Imports" function, which deleted some imports, and now it is comparing deployed code to the organized one. – Kocus May 24 '11 at 14:03
0

A quick suggestion would be, that the problem is somewhere in "inputStreamToByteArray(new PatchedInputStream(connectJava(url)));".

I am also wondering what "connectJava" is? Is it a method that you have created? If it is, please provide it too, as i suspect that it's causing the problem.

Rasmus Øvlesen
  • 510
  • 3
  • 8
  • I was just curious how the code like this could throw NPE in that line. Ok, it is possible (but very unlikely) that the bug is in one of my: `inputStreamToByteArray()`, `PatchedInputStream`, `connectJava( )`. – Kocus May 24 '11 at 13:57