while(true)
{
String input = "";
try {
input = in.readLine();
} catch (IOException e1) {
// TODO Auto-generated catch block
System.out.println(e1 + "Exception occured when reading user input");
}
// Sleep
try
{
Thread.sleep(USER_THROTTLE);
}
catch(Exception e)
{
System.out.println(toString()+" has input interrupted.");
}
if(input .equals("w")){action_event(input);}
if(input .equals("a")){action_event(input);}
if(input .equals("s")){action_event(input);}
if(input .equals("d")){action_event(input);}
if(input .equals("eat")){action_event(input);}
if(input .equals("drink")){action_event(input);}
if(input .equals("place")){action_event(input);}
if(input .equals("swim")){action_event(input);}
if(input .equals("command_kill")){action_event(input);}
if(input .equals("help")){action_event(input);}
}
}
Here is the stack trace
Exception in thread "Thread-1" java.lang.NullPointerException
at Platypus_User$Inport.run(Platypus_User.java:64)
This is being ran in Eclipse on Mac OSX. A Null Pointer Exception occurs following the second catch block where the string is compared to "w" then if it is "w" the action_event method is called.
I have no clue why this would be happening. I would appreciate any advice.
Set#contains()though such code repetitions make code look dirty