Java – NullPointerException – How can this happen?

NullPointerException – How can this happen?… here is a solution to the problem.

NullPointerException – How can this happen?

The code is as follows:

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

Get an 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(
ERROR/AndroidRuntime(4526):     at com.n.common.AsyncNetworking$
ERROR/AndroidRuntime(4526):     at
ERROR/AndroidRuntime(4526):     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(
ERROR/AndroidRuntime(4526):     at java.util.concurrent.ThreadPoolExecutor$
ERROR/AndroidRuntime(4526):     at

How is this possible?

EDIT: This may be due to the use of Eclipse’s Organize Import feature, which changes the line numbering – and compares the newer code version with the older code version that has been deployed. Thank you all for your help.


It should be a deployment issue or an issue related to saving files and having multiple versions. Line 185 of the code that throws the exception must be different from the code you posted.

Try cleaning/recompiling/ (redeploying) and see if the line number changes

Related Problems and Solutions