I am new to Java and I want to make an audio sequencer. So I've started with a class for sounds and I have this:
public class Sb {
public static AudioInputStream audioInputStream;
public static File file;
public static Clip clip;
Sb(String a){
try {
file = new File(a);
audioInputStream = AudioSystem.getAudioInputStream(file);
}
catch (UnsupportedAudioFileException u) {
}
catch(IOException i) {
}
catch(NullPointerException n) {
}
}
public static void play(){
clip.start();
}
}
I declare an instance like:
public static Sb hats = new Sb("file path");
And when I run hats.play()
I get:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
Any ideas how I can make this class work?
Thanks!
Edit:
Modified Constructor:
Sb(String a) throws UnsupportedAudioFileException, IOException, LineUnavailableException {
file = new File(a);
audioInputStream = AudioSystem.getAudioInputStream(file);
clip = AudioSystem.getClip();
}
But when I declare it now I get an error on this line:
public static Sb hats = new Sb("file path");
Error:
"unreported exception UnsuportedAudioFileException must be caught or declared to be thrown