NullPointerException - how could this happen?

got a code that looks 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 I got this exception:

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 this possible?

EDIT: This is probably due to the use of the "Organize Import" function of Eclipse, which changes line numbers and compares the new version of the code with the old one deployed. Thank you all for your help.

+3
source share
3 answers

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

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

+2
source

- , NPE. , , .

+2

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

I am also wondering what is "connectJava"? Is this the method you created? If so, please provide it, as I suspect this caused a problem.

0
source

All Articles