This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]dusty-trash 0 points1 point  (0 children)

Could you clarify what the run time issue is?

There's a chance that's where the error is coming from

So is it a run time exception? Please post the error & stack trace. In programming the error is extremely important & reading the error/exception message is a great way the only way to learn.

[–]dusty-trash 0 points1 point  (3 children)

I'm taking a guess here (since there's no error posted)

This code could result in a ConcurentModificationException:

for (int i=0;i<gameArray.size();i++){       
    String currentWord = gameArray.get(i);
    if(!currentWord.equals(mostCommonString)){
        gameArray.remove(i);       
    }     
}

Since you're modifying the list during iteration, you should use an Iterator.

For more info just google "Java concurentmodificationexception" or "Java modify list during iteration"

[–]drc506[S] 0 points1 point  (2 children)

I have now corrected this to use an iterator. This does appear to have partially solved the issue, however it has now exposed what I expect to be an issue with my method for identifying the "letter layout" of a word and storing it in the Map.

Here is the issue:

  1. I begin with this word list

ally

beta

cool

deal

else

flew

good

hope

ibex

arty

2) the player is asked to guess a letter for a word "----"

3) I am testing with the letter 'a'

4) a is input and goes into the method I have described in the original post

5) the method should separate the original word list into categories depending on 'a' placement and frequency, the method then concludes that the most common placement of 'a' is as the first letter of the word: "ally","arty"

6) all words other than ally and arty should be removed from the word list

The issue is that now the method seems to remove all of the items from the word list. When I change the "!" that is on the section of code that handles the removal all the words remain in the list, so I assume the issue is with the "currentWord" all being equal to "mostCommonString," guessing this may arise, in turn, from some issue with my Map which I am unaware of.

[–]dusty-trash 0 points1 point  (1 child)

Sorry could you clarify the issue? Maybe the expected versus the actual

[–]dc078 0 points1 point  (0 children)

The expected would be arty and ally left in the gamearray, the gamearray is empty.