Add null checks for these places. There are cases where the connection has errored out and a reconnection is attempted, the packetreader/writer is set to null, and notifyConnectionError() gets called; this would have resulted in NPE.