i use netbeans and i have this code thru which i play an audio clip
now, i want that when the user presses next button on the JFrame. the frame disposes another opens and the clip stops.
here is my code:
this goes in the mose released event of the button:
Reg1 ro = new Reg1();
ro.setVisible(true);
clip.close();
this.dispose();
this goes in main:
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
Welcome1 insta = new Welcome1();
insta.setVisible(true);
KeyListener s;
try {
AudioInputStream audio = AudioSystem.getAudioInputStream(new File("x.wav"));
Clip clip = AudioSystem.getClip();
clip.open(audio);
clip.start();
}
catch(UnsupportedAudioFileException uae) {
System.out.println(uae);
}
catch(IOException ioe) {
System.out.println(ioe);
}
catch(LineUnavailableException lua) {
System.out.println(lua);
}
}
});
it shows an error in the line clip.close();
What shoud I do to remove the error?
Please explain your answer as I am a newbie.
The error is:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code
at Welcome1.jButton2MouseReleased(Welcome1.java:60)
at Welcome1.access$000(Welcome1.java:7)
at Welcome1$1.mouseReleased(Welcome1.java:29)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:273)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
What i needed to do was initialise the variables under the class, rather that under main… as simple as that