View Single Post
  #17   Spotlight this post!  
Unread 03-02-2012, 09:38
derekwhite's Avatar
derekwhite derekwhite is offline
Java Virtual Machine Hacker
no team (FIRST@Oracle)
Team Role: Programmer
 
Join Date: May 2009
Rookie Year: 2009
Location: Burlington, MA
Posts: 127
derekwhite is on a distinguished road
Re: We got Sockets working

That stack trace suggests that the variable "you" is null at line 40. But it looks like that would only happen if acceptAndOpen() throw an exception, and no exception was printed in the output you showed.

An aside about NullPointerExceptions - for how common these are, they can really only be created by:
  • Trying to get or set a field using an object reference that is null:
    thisIsNull.field = 1;
  • Trying to get or set an array element using an object reference that is null:
    thisIsNull[0] = 1;
  • Trying to get the array length using an object reference that is null:
    thisIsNull.length;
  • Trying to call a non-static method on an object reference that is null:
    thisIsNull.toString();
  • Trying to synchronize an object reference that is null:
    synchronize(thisIsNull) ...
  • Throwing a NullPointerException! This is not too common, but some likely cases are:
    System.arraycopy(), Hashtable.contains().
    In Java SE (not on robot), native methods may throw a NullPointerException. It depends on the method.

For now I suggest adding code that explicitly checks for "you" being null or not.

I hope this helps track down the bug.
Reply With Quote