I am having problem with this code:
package javaapplication16; import java.io.InputStream; import javax.swing.JOptionPane; import sun.audio.AudioPlayer; import sun.audio.AudioStream; public class JavaApplication16 { public static void main(String[] args) { NewJFrame n = new NewJFrame(); n.setVisible(true); InputStream is; is = this.getClass().getClassLoader().getResourceAsStream("samp.wav"); try { AudioStream audioStream; audioStream = new AudioStream(is); AudioPlayer.player.start(audioStream); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } } It is saying that
error: non-static variable this cannot be referenced from a static context is = this.getClass().getClassLoader().getResourceAsStream("samp.wav"); If I make the InputStream variable static then its telling me illegal start of expression. I have also removed the this keyword. Still the problem is not solving. How can fix it?
thisbe without an instance?