0

I built a method that returns a specific value, and this value is taken from a arraylist.

This value is being printed on my listview, so I'm calling the method on my listview adapter.

But sometimes (not always), my app crashes, because something happens with the arraylist.

Its really weird because this issue only happens sometimes.

Could you guys please tell what do I need to change on my code to run properly?

Errors:

java.util.ConcurrentModificationException at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:573) at com.example.*****.getCountry(MySQLReceiver.java:124)

My code

public int getCountry(int receiveUserId){

    for (Users user : getAllUsers()) {

        if (receiveUserId == user.getUserId()) {

            userCountry = user.getUserCountry();

        }

    }

    return userCountry;

}

Thank you.

user2744048
  • 111
  • 1
  • 2
  • 7

0 Answers0