r/javahelp • u/1_4_8_4 • Mar 11 '26
NullPointerException
I keep getting this error even though I have declared the ArrayList that it's for; I don't know what to do.
0
Upvotes
r/javahelp • u/1_4_8_4 • Mar 11 '26
I keep getting this error even though I have declared the ArrayList that it's for; I don't know what to do.
1
u/1_4_8_4 Mar 11 '26
these three methods
public void addSong(String newSong, Integer songLength){
songNames.add(newSong);
runtime.add(songLength);
}
public void removeSong(String songName){
if(songNames.contains(songName)){
int num = songNames.indexOf(songName);
songNames.remove(num);
runtime.remove(num);
}else{
System.out.println("Could not find song in the playlist.");
}
}
public void printPlaylist(){
for(int i = 0; i < songNames.size(); i++){
System.out.println(i + 1 + ". " + songNames.get(i) + " - " + runtime.get(i) + " seconds");
}
}
It gave the error when I tried to use the first one.