0

I have some problem with java.util.ConcurrentModificationException. When I deleted one characater or more in my autocompletetext I got force close. Anybody knows what happen with that ? and what is the solution for that problem ?

Thank You.

1 Answer 1

0

It looks like you are adding and deleting something from your collection at same point of time. By doing this, you are structurally modifying the collections more than once at single point of time. Hence you are getting java.util.ConcurrentModificationException, which is the result of "Fail-Fast" iterators being used in your collections. You can have a look at this link which explains fail-safe and fail-fast iterators. what-is-fail-safe-fail-fast-iterators-in-java-how-they-are-implemented and checkout the answer written by Stephen C.

Sign up to request clarification or add additional context in comments.

3 Comments

Do you have some example of code to solve that problem ?
It's pretty simple, like I said, if you are trying to modify your collection structurally at a same given point of time, the iterator which you are using to iterate through that collection will fail. Check this example snippet below: ArrayList<String> sampleList = new ArrayList<String>(); sampleList.add("hello"); sampleList.add("world"); Iterator<String> sampleListItr = sampleList.iterator(); //If you try to remove first item from list, your iterator fails sampleList.remove(0); while(sampleListItr.hasNext()){ System.out.println(sampleListItr.next()); } So try to avoid iterators.
You can avoid that problem by not using iterators. Java 8 provides you foreach method to help you iterate over any collections.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.