0
public class MusicPlayerAndLibraryForm extends javax.swing.JFrame {

SongPlayer SP = new SongPlayer();

int audioLength;
int audioPosition = 0;

AudioInputStream audioInputStream = null;

ArrayList<Song> songs = new ArrayList<Song>();
ArrayList<Song> songFileLibrary = new ArrayList<Song>();

String songFile;

Media media = new Media(songFile);

private MediaPlayer mediaPlayer = new MediaPlayer(media);
private Slider seekSlider = new Slider();


int currentMusicLibraryIndex = 0;
int currentSongFileIndex = 0;
public static int count;


public MusicPlayerAndLibraryForm() {
    initComponents();

}


private void jButtonPlayActionPerformed(java.awt.event.ActionEvent evt) {                                            


   String songName = jListMusicLibrary.getSelectedValue();
    songFile = jListSongFiles.getSelectedValue();



   SP.Stop();


   this.mediaPlayer.currentTimeProperty().addListener(new ChangeListener<Duration>() {
   @Override
   public void changed(ObservableValue<? extends Duration> observable, Duration oldValue, Duration newValue) {
       MusicPlayerAndLibraryForm.this.seekSlider.setValue(newValue.toSeconds());
   }
   });

   this.seekSlider.setOnMouseClicked(new EventHandler<MouseEvent>() {
       @Override
       public void handle(MouseEvent event) {
           MusicPlayerAndLibraryForm.this.mediaPlayer.seek(Duration.seconds(MusicPlayerAndLibraryForm.this.seekSlider.getValue()));
   }
   });

   jTextFieldSongPlaying.setText(songName);
   SP.PlayBack(songFile);
}   

The culprits seems to possibly be the "Media media = new Media(songFile); " and "private MediaPlayer mediaPlayer = new MediaPlayer(media)" lines. I am unsure as to why the program is returning this error. I believe that all of my objects have been instantiated so I do not know where the program is getting null instead of an object.

Mana
  • 97
  • 1
  • 14

1 Answers1

0

It is because your string is null and you are passing it as a parameter. It will throw Null pointer exception.

Check this -https://docs.oracle.com/javafx/2/api/javafx/scene/media/Media.html

Jitindra Fartiyal
  • 107
  • 1
  • 1
  • 5
  • I initialized the "String songFile" and it returned a "java.lang.IllegalArgumentException" error – Mana Mar 30 '18 at 04:19
  • Documentation says `java.lang.IllegalArgumentException - if the URI string has a null scheme.` So it’s not enough just to initialize that string, you need to provide a ‘valid’ String. I guess it expects a string that can be used to construct URI. – ikos23 Mar 30 '18 at 04:30
  • Check this - java.lang.NullPointerException - if the URI string is null. java.lang.IllegalArgumentException - if the URI string does not conform to RFC-2396 or, if appropriate, the Jar URL specification, or is in a non-compliant form which cannot be modified to a compliant form. java.lang.IllegalArgumentException - if the URI string has a null scheme. java.lang.UnsupportedOperationException - if the protocol specified for the source is not supported. – Jitindra Fartiyal Mar 30 '18 at 04:31
  • Can you elaborate on an URI String? How would I create a String that allows for it be constructed as URI? – Mana Mar 30 '18 at 04:35