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;
}

