Time to do some debugging to see what the code is doing. Try debugging your code by adding println() statements to show execution progress and how variable values are changing. For example:
Add a: ...
Type: Posts; User: Norm
Time to do some debugging to see what the code is doing. Try debugging your code by adding println() statements to show execution progress and how variable values are changing. For example:
Add a: ...
One potential problem I see is having class variables and local/method variables with the same name.
There are a lot of variables named: word. Change the class variable to have a different name...
What prints out when you added the println statements?
What are the values of these as the loop executes: word.charAt(l) and userLetter
Also print out this: word.length()
Try debugging the code by adding some println statements that print out messages as the code executes and prints out the values of the variables that control the execution flow.
Please edit your...
Please explain.
See the String class's API doc for its methods:
Java Platform SE 7
If word is a String object, you need to use a method (ends with ()s) to get its length. The String class does not have a length member.
There are two different variables used in the posted code. The code should use the same one in both places.
wordSoFar
and
word
Use the length of word to control the loop. Get rid of...
Post the new code and the full text of the error message.
The error says that the index used in charAt() on line 172 is past the end of the String. Check that the String has a length > 0 before trying to get the first character in the String.
One way...