java - Why does this WAV file not play? It gives me a NullPointerException -
package net.nitrocruze.mrpg.baseengine.music; import java.io.file; import java.io.fileinputstream; import java.io.ioexception; import javax.sound.sampled.audioformat; import javax.sound.sampled.audioinputstream; import javax.sound.sampled.audiosystem; import javax.sound.sampled.clip; import javax.sound.sampled.dataline; import javax.sound.sampled.line; import javax.sound.sampled.lineunavailableexception; public class cpsound implements runnable{ audioinputstream as1; audioformat af; clip clip1; dataline.info info; line line1; public cpsound() { thread soundthread; soundthread = new thread(this, "sound"); soundthread.start(); } public void play() { try{ as1 = audiosystem.getaudioinputstream(new fileinputstream(new file("/res/music.wav"))); af = as1.getformat(); clip1 = audiosystem.getclip(); info = new dataline.info(clip.class, af); line1 = audiosystem.getline(info); } catch(exception e) { } if ( ! line1.isopen() ) { try { clip1.open(as1); } catch (exception e) { } clip1.loop(clip.loop_continuously); clip1.start(); } } public void run() { play(); } }
why not work? gives me nullpointerexception
?
i found out why wasn't working! had put "/" before 'res/music.wav' caused file loading system think loading drive (eg c:/ f:/), there nothing before / thought loading null drive, cannot exist.
Comments
Post a Comment