Issue
Why am I getting a
Null pointer access: The variable versionFromInputStream can only be null at this location
Error? Is that because the IDE doesn't know about the read method?
byte[] versionFromInputStream = null;
if (input.read(versionFromInputStream, 0, 3) != 3)
{
throw new NetworkException();
}
double version = Double.parseDouble(versionFromInputStream.toString());
Solution
So you've got a couple of things going on here that aren't right
byte[] versionFromInputStream = null; // you should initialize this like = new byte[2048]; because..
if (input.read(versionFromInputStream, 0, 3) != 3) // because here you are trying to read into this byte array. And because it hasn't been initialized, you are getting the exception
{
throw new NetworkException();
}
double version = Double.parseDouble(versionFromInputStream.toString()); // this isn't going to work either. byte[].toString is the same as Object.toString - it just prints out the location of the object in virtual memory, which isn't what you want
Answered By - ControlAltDel