Thanks for the help. It was and error with having variable equal b instead of b equals variable.
Asked
Active
Viewed 277 times
1
-
possible duplicate of [How do I compare strings in Java?](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – Pshemo Nov 18 '13 at 01:42
-
You should also read [how-to-avoid-java-code-in-jsp-files](http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files) – Pshemo Nov 18 '13 at 01:43
-
Are you sure there isn't any whitespace in there fouling things up? Try `'<%= useranswer[0] %>'` (wrapped in single quotes) to check. – matt Nov 18 '13 at 01:45
-
Tried what you suggested, no whitespaces. – user2532973 Nov 18 '13 at 01:51
1 Answers
0
Use if (useranswer[0].equals("b")) instead. equals means the string are same.
But == means they are same object in memory.
-
did you post your exact code? If you're getting a null pointer exception with that call, that probably means that `useranswer[0]` is null. – matt Nov 18 '13 at 02:01
-
Always use const value first when you compare: `"b".equals(useranswer[0])` That'll prevent NullPointerExceptions. – regulus Nov 18 '13 at 02:05