So, I have a this ObjectInputStream which most of the time will be null. (It is for a chat server.) I thought this code would take care of null conditions. (This is in it's own thread so that it doesn't block the rest of the program. The previous solution that I am rewriting to send objects, not strings, used to block until it got something. I am looking for a way to have similar behavior.)
When the program runs, I get a null pointer exception here. (Because the value is null obviously!) How can I get the stream to wait until it receives something to try and read it? (or to keep trying until it gets something that isn't null?).
while((message = (Message)JavaChat.connection.oInStream.readObject()) != null)
{
// ...do some stuff...
}
EDIT: Stack trace. (Seems a little short no?)
java.lang.NullPointerException
at javachat2.IncomingReader.run(IncomingReader.java:33)
at java.lang.Thread.run(Thread.java:745)
Am I missing something obvious here?