Есть проблема с этим кодом
package MILES; import java.io.IOException; import java.net.URL; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip; import javax.sound.sampled.DataLine; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.Mixer; import javax.sound.sampled.UnsupportedAudioFileException; import com.sun.tools.script.shell.Main; public class Audio { public static Mixer mixer; public static Clip clip; public static void main(String[] args) { // TODO Auto-generated method stub // Creating an Array of Mixer info on my system. Mixer.Info[] mixInfos = AudioSystem.getMixerInfo(); /* for (Mixer.Info info : mixInfos) { System.out.println(info.getName() + " ---- " + info.getDescription()); }*/ // Getting the mixer mixer = AudioSystem.getMixer(mixInfos[2]); // DataLine for the audio port. Get information about the line before we can actually get the line. DataLine.Info dataInfo = new DataLine.Info(Clip.class, null); try { clip = ((Clip)mixer.getLine(dataInfo)); } catch (LineUnavailableException lue ) { lue.printStackTrace(); } //Getting the path for the music. Get resource inside the class try { URL soundURL = Main.class.getResource("/MILES/sounds.wav"); AudioInputStream audioStream = AudioSystem.getAudioInputStream(soundURL); clip.open(audioStream); } catch(IOException ioe) { ioe.printStackTrace(); } catch(LineUnavailableException lue ) { lue.printStackTrace(); } catch(UnsupportedAudioFileException uaf) { uaf.printStackTrace(); } clip.start(); do { try { Thread.sleep(50); } catch (InterruptedException ie) { ie.printStackTrace(); } } while (clip.isActive()); } }
Это дает мне ошибку
Exception in thread "main" java.lang.NullPointerException at java.base/java.util.Objects.requireNonNull(Unknown Source) at java.desktop/javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source) at MILES.Audio.main(Audio.java:47)
Что я уже пробовал:
Изменение индекса для mixInfos и это приведет к другим проблемам.