I want to create a play() method with Track in the method parameters but I can't do this in my controller class as the play is an action and actions can't have parameters (or it must be an ActionEvent).
So I thought of creating another class to apply play logic instead and just pass to this method in the new class instead of doing everything there.
@FXML
private void play() {
play.setText("Pause");
Track selectedTrack = playingTable.getSelectionModel().getSelectedItem();
if (selectedTrack != null && selectedTrack != playingTrack) {
player.stopSong();
player = new TrackPlayer(selectedTrack);
playingTrack = selectedTrack;
player.playSong();
} else {
switch (player.getStatus()) {
case READY:
player.playSong();
break;
case PLAYING:
player.pauseSong();
play.setText("Play");
break;
case PAUSED:
player.playSong();
play.setText("Pause");
break;
default:
System.out.println("Wtf?");
}
}
updateInfo();
}
This is my play() method now inside my controller class (which is working correctly). I want to change it so I can do the following
if(selectedTrack != null) {
manager.play(selectedTrack);
} else {
System.out.println("Track not selected / null");
}
manager being another class which would have the following method
public void play(Track track) {
controller.setPlayTxt("Pause");
if (track != null && track != playingTrack) {
player.stopSong();
player = new TrackPlayer(track);
playingTrack = track;
player.playSong();
} else {
switch (player.getStatus()) {
case READY:
player.playSong();
break;
case PLAYING:
player.pauseSong();
controller.setPlayTxt("Play");
break;
case PAUSED:
player.playSong();
controller.setPlayTxt("Pause");
break;
default:
System.out.println("Wtf?");
}
}
}
However whenever I click on a song (that is not null) and press play I get a NullPointerException on the line manager.play(selectedTrack);
Why? I know that the object is not null, and have checks for it, and this is the exact same way I do it originally (which works) but when I change this to be a pass to another class I get NullPointerException.