Can anyone help me with a very strange error I am getting? What happens is:
I read some binary data from an http conection into a byte array and return it:
DataInputStream dis=new DataInputStream(is);
serverData=new byte[ buffLen=(((int)serverData)&0xff)|((((int)serverData)<<8)&0xff00) ];
//note the first 2 bytes are the length of the rest of the data.
the function returns and the calling function parses the data after printing it. At least it should..
this prints the following:
and then it stops..
the emulator screen says there is a null pointer exception. It never prints "DonePrintingServerData" or even reaches the 6042th
byte. Just stops there. It also does not print any of the many e.printStackTrace()'s from the try/catch blocks that it is
wrapped in at different levels, not even the one in the run() method inside of which all function calls originate. Which is to
bad because I also have it set up to display a message on the actual phone, and prevent a complete app crash should any of those
catch blocks catch anything. (with this bug it doesnt seem to matter)
If I comment out the printing section it works fine on the EMULATOR and parses everything perfectly. It parses ALL of the data
that is comming in from my servlet, and it does it correctly.
So as wierd as that seems, I try running it on an actual phone after removing the System.out.println()'s and that print loop. I
get the same null pointer error at the same point in execution. I can tell that it is in that point of execution because of were
the app is when it crashes, not because of any thing I get back, because all i get back is the white default null pointer
I am at a loss here. There are no other threads working in my app. It doesnt matter if I make the byte array a static data
member of the class, or if I return it, or even if I make a byte serverData=new byte and pass it into the http request
function and assign the data to serverData=byteArrayData; to bypass how java passes references by value to return it through
a function paramater. But its as if the array is garbage collected when it shouldnt be or something. The only things refrenced
in that loop is the serverData and System.out. How could this happen?
One of our other programmers thinks that the array is not totaly inintialized, but its a byte array, not an object array. I dont
know, if any one has any ideas I would greatly appreciate hearing from you.
oh, btw, this is the second time this function executes when this happens. It uses the same function to parse all server data regardless of the request/response. The first time it works perfectly on both the phone and the emulator. It is the second time that the phone accesses the web that it crashes like this. Dont know if that helps.