[Solved] List 70 albums is not working, only appears 3 albums and are repeated [closed]


There is a LOT of problem in your code…

First, the loop :

ArrayList<ArrayList<String>> result;
// the error maybe is in this part:
for (int i = 0; i<= result1.size(); i++)
    result = qm.getAlbumInfo(name[i], id[i]);

You will only get the last qm.getAlbumInfo(name[i], id[i]) as a result.

You probably want to add every List<String> (if this is the return type of getAlbumInfo) into a List. Without that, you will not keep every result.

 List<<List<String>> result = new ArrayList<List<String>>();
 for (int i = 0; i<= result1.size(); i++)
    result.add(qm.getAlbumInfo(name[i], id[i]));

If am a bit worried about the condition of the loop, if you start at i = 0, you most likely need to check for i < result1.size, not i <= result1.size

But then, name[i] and id[i] can’t compile since those are String.

The way you get those String are wrong too :

ArrayList<ArrayList<String>> result1 = qm1.getAlbums();
qm1.closeConnections();

String name =  result1.get(0).toString();
String id   =  result1.get(1).toString();

The return of result1.get is a ArrayList<String>, so I doubt tostring is what you expect.

From all that. I would guess that the actual code you want is :

List<List<String>> resultAlbum = qm1.getAlbums();

List<String> albumInfo;
String name, id;
List<<List<String>> resultInfo = new ArrayList<List<String>>();
for (int i = 0; i<= resultAlbum.size(); i++){
    //get on album row
    albumInfo = resultAlbum.get(i);

    name = albumInfo.get(0);
    id = albumInfo.get(1);

    //Get the info for this album and add into the list
    resultInfo .add(qm.getAlbumInfo(name, id));
}

solved List 70 albums is not working, only appears 3 albums and are repeated [closed]