Sorting ArrayList - IndexOutOfBoundsException -Java

Posted by FILIaS on Stack Overflow See other posts from Stack Overflow or by FILIaS
Published on 2011-01-13T05:02:22Z Indexed on 2011/01/13 5:54 UTC
Read the original article Hit count: 446

Filed under:
|
|

I'm trying to sort an ArrayList with strings(PlayersNames) and imageIcons(PlayersIcons) based on the values i store in an other arrayList with integers(results). As you can see i get an indexOutOfBoundsException but i cant understand why. Maybe the earling of the morning makes me not to see plain things.

ArrayList<String> PlayersNames=new ArrayList<String>;
ArrayList<ImageIcon> PlayersIcons=new ArrayList<ImageIcons>;

    public void sortPlayers(ArrayList<Integer> results){
        String tmp;
        ImageIcon tmp2;
        for (int i=0; i<PlayersNames.size(); i++) {
            for (int j=PlayersNames.size(); j>i; j--) {

                if (results.get(i) < results.get(i+1) ) {       //IndexOutOfBoundsException!

                    tmp=PlayersNames.get(i+1);
                    PlayersNames.set(i+1,PlayersNames.get(i));
                    PlayersNames.set(i,tmp);

                    tmp2=PlayersIcons.get(i+1);
                    PlayersIcons.set(i+1,PlayersIcons.get(i));
                    PlayersIcons.set(i,tmp2);
                }
            }
        }
    }

© Stack Overflow or respective owner

Related posts about java

Related posts about sorting