Defensive programming:
this isn't directly related to your problem, but rather than writing
variable.equals("string") try to get into the practice of writing
"string".equals(variable)
They are nearly the same but the latter returns false for null rather than throwing an NPE.
You can do the same with many
Java classes eg new Integer(0).equals(var)