NullPointerException

Hi everyone! Im relatively new to java so im too comfortable with the exception notion. I do understand what most of them mean but im not sure how i can fix them. So here's my problem:

My code works fine. But if i do print the exception caught, i get a nullPointerException. Again, i could just remove the "System.out" command in the "catch" section but i would much rather know what im doing wrong. Any thoughts?

Thank you!

public String buildString ( BufferedReader in ){

//this method reads every line from a given file and returns a single String consisting

//only of characters. No spaces.

String result = "";

String s;

try{

while ( ( s = in.readLine().trim()) != null ){

StringTokenizer st = new StringTokenizer( s );

while (st.hasMoreTokens()){

String temp = st.nextToken();

result = result + temp;

}

}

in.close();

}catch(Exception e) {System.out.println(e);}

return result;

}

[1005 byte] By [Bruised_Leea] at [2007-11-26 22:47:31]
# 1
while ( ( s = in.readLine().trim()) != null )What's that trim() call going to do when in.readLine() returns null? =)
BinaryDigita at 2007-7-10 12:06:31 > top of Java-index,Java Essentials,New To Java...
# 2
What he said.:-)Stack traces are invariably more useful than simply printing the exception, especially for diagnosing problems like this. You would have seen that the exception originated in String.trim().
deepravea at 2007-7-10 12:06:31 > top of Java-index,Java Essentials,New To Java...
# 3
wow!you guys are the best!thanks a lot!!!!
Bruised_Leea at 2007-7-10 12:06:31 > top of Java-index,Java Essentials,New To Java...