what I am trying to do is to get 2 playlists from website. But when i get lists it fills first list with good items. and in the second it puts first and adds second…. and i dont ged it why.
So I get it with:
conn = (HttpURLConnection) url.openConnection();
BufferedReader rd = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
parseMusic(rd,choice);
conn.disconnect();
and hier i try to put in 2 playlist (not simultaneously). So I call it 2 times. Query’s on website returns wright lists.
It goes with PLchoice and in first and in second case.. thaths why i get second list wright and first is second+first one… why?
private void parseMusic(BufferedReader reader,int PLchoice) throws IOException {
String line=null;
while((line = reader.readLine()) != null) {
String[] values = line.split(",");
switch (PLchoice){
case 1: {
if(musicList != null) {
if(values[0].equals("null")) {
Log.e("ERROR", "no music found!");
} else {
int id = Integer.parseInt(values[0]);
String filename = values[1];
musicList.add(new Mp3(id, filename));
}
} else {
Log.e("ERROR", "MusicList = null");
}
}
case 3:{
if(secondList != null) {
if(values[0].equals("null")) {
Log.e("ERROR", "no music found!");
} else {
int id = Integer.parseInt(values[0]);
String filename = values[1];
secondList.add(new Mp3(id, filename));
}
} else {
Log.e("ERROR", "MusicList = null");
}
}
}
}
reader.close();
Log.e("playList","MP3 file muslist= "+musicList);
Log.e("playList added","MP3 file secondList= "+secondList);
}
You need to
breakout of each case statement (the brackets are also unnecessary).Java Switch Documentation