Results 1 to 5 of 5
- 03-15-2011, 12:55 PM #1
Member
- Join Date
- Feb 2011
- Location
- Germany
- Posts
- 7
- Rep Power
- 0
Need help with IllegalStateException
Hello everybody,
I am currently building a fairly simple soundboard as a surprise for a friend. I got it that far, that the sounds play according to the button pressed. However I do have two major problems:
1. When I play a sound and press another button after and/or while playing back the first sound, I get an IllegalStateException and the program crashes.
2. I currently access the sound files (waves) using the absolute paths and I cannot find a solution to get those files working from an executable jar file.
I have read many threads here and in other forums already but I cannot get this solved. Please help me! Any tip is highly appreciated. Thanks a lot!
Here is the current code:
Java Code:package fun; import java.applet.*; import java.awt.*; import java.awt.event.*; import java.io.*; import java.net.URL; import javax.swing.*; class GUI extends JFrame implements ActionListener { final InputStream in = GUI.class.getResourceAsStream("./META-INF/sound/1.wav"); File sound1 = new File ( "/home/noneofthem/Dropbox/workspace/Mike/META-INF/sound/1.wav" ); File sound2 = new File ( "/home/noneofthem/Dropbox/workspace/Mike/META-INF/sound/2.wav" ); File sound3 = new File ( "/home/noneofthem/Dropbox/workspace/Mike/META-INF/sound/3.wav" ); File sound4 = new File ( "/home/noneofthem/Dropbox/workspace/Mike/META-INF/sound/4.wav" ); File sound5 = new File ( "/home/noneofthem/Dropbox/workspace/Mike/META-INF/sound/5.wav" ); File sound6 = new File ( "/home/noneofthem/Dropbox/workspace/Mike/META-INF/sound/6.wav" ); File sound7 = new File ( "/home/noneofthem/Dropbox/workspace/Mike/META-INF/sound/7.wav" ); File sound8 = new File ( "/home/noneofthem/Dropbox/workspace/Mike/META-INF/sound/8.wav" ); File sound9 = new File ( "/home/noneofthem/Dropbox/workspace/Mike/META-INF/sound/9.wav" ); File sound10 = new File ( "/home/noneofthem/Dropbox/workspace/Mike/META-INF/sound/10.wav" ); File sound99 = new File ( "/home/noneofthem/Dropbox/workspace/Mike/META-INF/sound/99.wav" ); public GUI () { super ( "MikeBoard 1.0" ); this.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE ); this.setSize ( new Dimension ( 710, 140 ) ); this.setLocationRelativeTo ( null ); Font mainFont = new Font ( "Verdana", 1, 14 ); JPanel mainPanel = new JPanel(); mainPanel.setBackground ( Color.getHSBColor ( 255, 153, 51 ) ); mainPanel.setLayout ( new FlowLayout ( FlowLayout.CENTER ) ); final JButton button1 = new JButton ( "Keine Zeit" ); final JButton button2 = new JButton ( "Bis 7 Uhr" ); final JButton button3 = new JButton ( "Und dann..." ); final JButton button4 = new JButton ( "Kaffee" ); final JButton button5 = new JButton ( "Er ist froh" ); final JButton button6 = new JButton ( "Isolation" ); final JButton button7 = new JButton ( "Probleme" ); final JButton button8 = new JButton ( "Es hilft" ); final JButton button9 = new JButton ( "Die anderen" ); final JButton button10 = new JButton ( "Hilfe holen" ); JButton[] buttonArray = new JButton[] { button1, button2, button3, button4, button5, button6, button7, button8, button9, button10, }; for ( JButton button : buttonArray ) { button.setFont ( mainFont ); button.setBackground ( Color.getHSBColor ( 255, 255, 204 ) ); button.setForeground ( Color.WHITE); button.setPreferredSize ( new Dimension ( 135, 50 ) ); button.addActionListener ( this ); mainPanel.add ( button ); } JPanel mainBox = new JPanel(); mainBox.setLayout ( new BoxLayout ( mainBox, BoxLayout.Y_AXIS ) ); mainBox.add ( mainPanel ); this.add ( mainBox ); this.setResizable ( false ); this.setVisible ( true ); } // END of GUI constructor public void actionPerformed ( ActionEvent e ) { if ( e.getActionCommand().equalsIgnoreCase ( "keine zeit" ) ) { playSound ( sound1 ); } else if ( e.getActionCommand().equalsIgnoreCase ( "bis 7 uhr" ) ) { playSound ( sound2 ); } else if ( e.getActionCommand().equalsIgnoreCase ( "und dann..." ) ) { playSound ( sound3 ); } else if ( e.getActionCommand().equalsIgnoreCase ( "kaffee" ) ) { playSound ( sound4 ); } else if ( e.getActionCommand().equalsIgnoreCase ( "er ist froh" ) ) { playSound ( sound5 ); } else if ( e.getActionCommand().equalsIgnoreCase ( "isolation" ) ) { playSound ( sound6 ); } else if ( e.getActionCommand().equalsIgnoreCase ( "probleme" ) ) { playSound ( sound7 ); } else if ( e.getActionCommand().equalsIgnoreCase ( "es hilft" ) ) { playSound ( sound8 ); } else if ( e.getActionCommand().equalsIgnoreCase ( "die anderen" ) ) { playSound ( sound9 ); } else if ( e.getActionCommand().equalsIgnoreCase ( "hilfe holen" ) ) { playSound ( sound10 ); } } // END of actionPerformed private synchronized void playSound(File file) { try { AudioClip test = Applet.newAudioClip ( file.toURL() ); test.play(); } catch ( Exception e4 ) { e4.printStackTrace(); } } // END of playSound } // END of GUI class
Java Code:package fun; public class MikeBoard { public static void main(String[] args) { GUI mainGUI = new GUI(); } // END of main } // END of MikeBoard
- Lubuntu 10.10, Eclipse 3.5.2, Python 2.6.6, Java 6 -
- 03-15-2011, 01:27 PM #2I get an IllegalStateException and the program crashes.
db
- 03-15-2011, 01:35 PM #3
Member
- Join Date
- Feb 2011
- Location
- Germany
- Posts
- 7
- Rep Power
- 0
Here is the exception I get. Sorry but my head is not working correctly today. Getting confused and frustrated right now...
Java Code:Exception in thread "PulseAudio Eventloop Thread" java.lang.IllegalStateException: drain failed at org.classpath.icedtea.pulseaudio.EventLoop.native_iterate(Native Method) at org.classpath.icedtea.pulseaudio.EventLoop.run(EventLoop.java:141) at java.lang.Thread.run(Thread.java:636)
- Lubuntu 10.10, Eclipse 3.5.2, Python 2.6.6, Java 6 -
- 03-15-2011, 07:46 PM #4
Member
- Join Date
- Feb 2011
- Location
- Germany
- Posts
- 7
- Rep Power
- 0
UPDATE:
I got it working now! The only thing I couldn´t figure out yet is how to access the sound files from within an executable jar file, so I would be grateful for any advise you can give me! Many thanks in advance! :-)
Here is the updated code:
Java Code:package fun; import java.applet.*; import java.awt.*; import java.awt.event.*; import java.io.*; import java.net.MalformedURLException; import java.util.ArrayList; import javax.swing.*; class GUI extends JFrame implements ActionListener { ArrayList <AudioClip> soundArray = new ArrayList<AudioClip>(); AudioClip ac1; AudioClip ac2; AudioClip ac3; AudioClip ac4; AudioClip ac5; AudioClip ac6; AudioClip ac7; AudioClip ac8; AudioClip ac9; AudioClip ac10; public GUI () { super ( "MikeBoard 1.0" ); this.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE ); this.setSize ( new Dimension ( 710, 140 ) ); this.setLocationRelativeTo ( null ); Font mainFont = new Font ( "Verdana", 1, 14 ); JPanel mainPanel = new JPanel(); mainPanel.setBackground ( Color.getHSBColor ( 255, 153, 51 ) ); mainPanel.setLayout ( new FlowLayout ( FlowLayout.CENTER ) ); final JButton button1 = new JButton ( "Keine Zeit" ); final JButton button2 = new JButton ( "Bis 7 Uhr" ); final JButton button3 = new JButton ( "Und dann..." ); final JButton button4 = new JButton ( "Kaffee" ); final JButton button5 = new JButton ( "Er ist froh" ); final JButton button6 = new JButton ( "Isolation" ); final JButton button7 = new JButton ( "Probleme" ); final JButton button8 = new JButton ( "Es hilft" ); final JButton button9 = new JButton ( "Die anderen" ); final JButton button10 = new JButton ( "Hilfe holen" ); JButton[] buttonArray = new JButton[] { button1, button2, button3, button4, button5, button6, button7, button8, button9, button10, }; for ( JButton button : buttonArray ) { button.setFont ( mainFont ); button.setBackground ( Color.getHSBColor ( 255, 255, 204 ) ); button.setForeground ( Color.WHITE); button.setPreferredSize ( new Dimension ( 135, 50 ) ); button.addActionListener ( this ); mainPanel.add ( button ); } File sound1 = new File ( "/home/noneofthem/Dropbox/workspace/Mike/META-INF/sound/1.wav" ); File sound2 = new File ( "/home/noneofthem/Dropbox/workspace/Mike/META-INF/sound/2.wav" ); File sound3 = new File ( "/home/noneofthem/Dropbox/workspace/Mike/META-INF/sound/3.wav" ); File sound4 = new File ( "/home/noneofthem/Dropbox/workspace/Mike/META-INF/sound/4.wav" ); File sound5 = new File ( "/home/noneofthem/Dropbox/workspace/Mike/META-INF/sound/5.wav" ); File sound6 = new File ( "/home/noneofthem/Dropbox/workspace/Mike/META-INF/sound/6.wav" ); File sound7 = new File ( "/home/noneofthem/Dropbox/workspace/Mike/META-INF/sound/7.wav" ); File sound8 = new File ( "/home/noneofthem/Dropbox/workspace/Mike/META-INF/sound/8.wav" ); File sound9 = new File ( "/home/noneofthem/Dropbox/workspace/Mike/META-INF/sound/9.wav" ); File sound10 = new File ( "/home/noneofthem/Dropbox/workspace/Mike/META-INF/sound/10.wav" ); try { ac1 = Applet.newAudioClip ( sound1.toURL() ); soundArray.add ( ac1 ); } catch ( MalformedURLException e ) { e.printStackTrace(); } try { ac2 = Applet.newAudioClip ( sound2.toURL() ); soundArray.add ( ac2 ); } catch ( MalformedURLException e ) { e.printStackTrace(); } try { ac3 = Applet.newAudioClip ( sound3.toURL() ); soundArray.add ( ac3 ); } catch ( MalformedURLException e ) { e.printStackTrace(); } try { ac4 = Applet.newAudioClip ( sound4.toURL() ); soundArray.add ( ac4 ); } catch ( MalformedURLException e ) { e.printStackTrace(); } try { ac5 = Applet.newAudioClip ( sound5.toURL() ); soundArray.add ( ac5 ); } catch ( MalformedURLException e ) { e.printStackTrace(); } try { ac6 = Applet.newAudioClip ( sound6.toURL() ); soundArray.add ( ac6 ); } catch ( MalformedURLException e ) { e.printStackTrace(); } try { ac7 = Applet.newAudioClip ( sound7.toURL() ); soundArray.add ( ac7 ); } catch ( MalformedURLException e ) { e.printStackTrace(); } try { ac8 = Applet.newAudioClip ( sound8.toURL() ); soundArray.add ( ac8 ); } catch ( MalformedURLException e ) { e.printStackTrace(); } try { ac9 = Applet.newAudioClip ( sound9.toURL() ); soundArray.add ( ac9 ); } catch ( MalformedURLException e ) { e.printStackTrace(); } try { ac10 = Applet.newAudioClip ( sound10.toURL() ); soundArray.add ( ac10 ); } catch ( MalformedURLException e ) { e.printStackTrace(); } JPanel mainBox = new JPanel(); mainBox.setLayout ( new BoxLayout ( mainBox, BoxLayout.Y_AXIS ) ); mainBox.add ( mainPanel ); this.add ( mainBox ); this.setResizable ( false ); this.setVisible ( true ); } // END of GUI constructor public void actionPerformed ( ActionEvent e ) { if ( e.getActionCommand().equalsIgnoreCase ( "keine zeit" ) ) { soundArray.get ( 0 ).play(); } else if ( e.getActionCommand().equalsIgnoreCase ( "bis 7 uhr" ) ) { soundArray.get ( 1 ).play(); } else if ( e.getActionCommand().equalsIgnoreCase ( "und dann..." ) ) { soundArray.get ( 2 ).play(); } else if ( e.getActionCommand().equalsIgnoreCase ( "kaffee" ) ) { soundArray.get ( 3 ).play(); } else if ( e.getActionCommand().equalsIgnoreCase ( "er ist froh" ) ) { soundArray.get ( 4 ).play(); } else if ( e.getActionCommand().equalsIgnoreCase ( "isolation" ) ) { soundArray.get ( 5 ).play(); } else if ( e.getActionCommand().equalsIgnoreCase ( "probleme" ) ) { soundArray.get ( 6 ).play(); } else if ( e.getActionCommand().equalsIgnoreCase ( "es hilft" ) ) { soundArray.get ( 7 ).play(); } else if ( e.getActionCommand().equalsIgnoreCase ( "die anderen" ) ) { soundArray.get ( 8 ).play(); } else if ( e.getActionCommand().equalsIgnoreCase ( "hilfe holen" ) ) { soundArray.get ( 9 ).play(); } } // END of actionPerformed } // END of GUI class
- Lubuntu 10.10, Eclipse 3.5.2, Python 2.6.6, Java 6 -
- 03-17-2011, 11:00 AM #5
Member
- Join Date
- Feb 2011
- Location
- Germany
- Posts
- 7
- Rep Power
- 0
UPDATE:
Everything is working alright now. I had some issues with incorrectly installed Java versions (OpenJDK vs. Sun JDK). After a reinstall of the OpenJDK, Eclipse and Netbeans, everything is working properly.
Here is the finished code, if anyone needs some code examples:
Java Code:package mikeboard; import java.applet.Applet; import java.applet.AudioClip; import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.net.URL; import java.util.ArrayList; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; class GUI extends JFrame implements ActionListener { ArrayList <AudioClip> soundArray = new ArrayList<AudioClip>(); AudioClip ac1; AudioClip ac2; AudioClip ac3; AudioClip ac4; AudioClip ac5; AudioClip ac6; AudioClip ac7; AudioClip ac8; AudioClip ac9; AudioClip ac10; public GUI () { super ( "MikeBoard 1.0" ); this.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE ); this.setSize ( new Dimension ( 710, 140 ) ); this.setLocationRelativeTo ( null ); Font mainFont = new Font ( "Verdana", 1, 14 ); JPanel mainPanel = new JPanel(); mainPanel.setBackground ( Color.getHSBColor ( 255, 153, 51 ) ); mainPanel.setLayout ( new FlowLayout ( FlowLayout.CENTER ) ); final JButton button1 = new JButton ( "Keine Zeit" ); final JButton button2 = new JButton ( "Bis 7 Uhr" ); final JButton button3 = new JButton ( "Und dann..." ); final JButton button4 = new JButton ( "Kaffee" ); final JButton button5 = new JButton ( "Er ist froh" ); final JButton button6 = new JButton ( "Isolation" ); final JButton button7 = new JButton ( "Probleme" ); final JButton button8 = new JButton ( "Es hilft" ); final JButton button9 = new JButton ( "Die anderen" ); final JButton button10 = new JButton ( "Hilfe holen" ); JButton[] buttonArray = new JButton[] { button1, button2, button3, button4, button5, button6, button7, button8, button9, button10, }; for ( JButton button : buttonArray ) { button.setFont ( mainFont ); button.setBackground ( Color.getHSBColor ( 255, 255, 204 ) ); button.setForeground ( Color.WHITE); button.setPreferredSize ( new Dimension ( 135, 50 ) ); button.addActionListener ( this ); mainPanel.add ( button ); } URL url1 = MikeBoard.class.getClassLoader().getResource ( "sound/1.wav" ); URL url2 = MikeBoard.class.getClassLoader().getResource ( "sound/2.wav" ); URL url3 = MikeBoard.class.getClassLoader().getResource ( "sound/3.wav" ); URL url4 = MikeBoard.class.getClassLoader().getResource ( "sound/4.wav" ); URL url5 = MikeBoard.class.getClassLoader().getResource ( "sound/5.wav" ); URL url6 = MikeBoard.class.getClassLoader().getResource ( "sound/6.wav" ); URL url7 = MikeBoard.class.getClassLoader().getResource ( "sound/7.wav" ); URL url8 = MikeBoard.class.getClassLoader().getResource ( "sound/8.wav" ); URL url9 = MikeBoard.class.getClassLoader().getResource ( "sound/9.wav" ); URL url10 = MikeBoard.class.getClassLoader().getResource ( "sound/10.wav" ); ac1 = Applet.newAudioClip ( url1 ); ac2 = Applet.newAudioClip ( url2 ); ac3 = Applet.newAudioClip ( url3 ); ac4 = Applet.newAudioClip ( url4 ); ac5 = Applet.newAudioClip ( url5 ); ac6 = Applet.newAudioClip ( url6 ); ac7 = Applet.newAudioClip ( url7 ); ac8 = Applet.newAudioClip ( url8 ); ac9 = Applet.newAudioClip ( url9 ); ac10 = Applet.newAudioClip ( url10 ); soundArray.add ( ac1 ); soundArray.add ( ac2 ); soundArray.add ( ac3 ); soundArray.add ( ac4 ); soundArray.add ( ac5 ); soundArray.add ( ac6 ); soundArray.add ( ac7 ); soundArray.add ( ac8 ); soundArray.add ( ac9 ); soundArray.add ( ac10 ); JPanel mainBox = new JPanel(); mainBox.setLayout ( new BoxLayout ( mainBox, BoxLayout.Y_AXIS ) ); mainBox.add ( mainPanel ); this.add ( mainBox ); this.setResizable ( false ); this.setVisible ( true ); } // END of GUI constructor public void actionPerformed ( ActionEvent e ) { if ( e.getActionCommand().equalsIgnoreCase ( "keine zeit" ) ) { soundArray.get ( 0 ).play(); } else if ( e.getActionCommand().equalsIgnoreCase ( "bis 7 uhr" ) ) { soundArray.get ( 1 ).play(); } else if ( e.getActionCommand().equalsIgnoreCase ( "und dann..." ) ) { soundArray.get ( 2 ).play(); } else if ( e.getActionCommand().equalsIgnoreCase ( "kaffee" ) ) { soundArray.get ( 3 ).play(); } else if ( e.getActionCommand().equalsIgnoreCase ( "er ist froh" ) ) { soundArray.get ( 4 ).play(); } else if ( e.getActionCommand().equalsIgnoreCase ( "isolation" ) ) { soundArray.get ( 5 ).play(); } else if ( e.getActionCommand().equalsIgnoreCase ( "probleme" ) ) { soundArray.get ( 6 ).play(); } else if ( e.getActionCommand().equalsIgnoreCase ( "es hilft" ) ) { soundArray.get ( 7 ).play(); } else if ( e.getActionCommand().equalsIgnoreCase ( "die anderen" ) ) { soundArray.get ( 8 ).play(); } else if ( e.getActionCommand().equalsIgnoreCase ( "hilfe holen" ) ) { soundArray.get ( 9 ).play(); } } // END of actionPerformed } // END of GUI class
- Lubuntu 10.10, Eclipse 3.5.2, Python 2.6.6, Java 6 -
Similar Threads
-
java.lang.IllegalStateException: OutputStream already retrieved
By jctet in forum Java ServletReplies: 12Last Post: 09-17-2010, 01:40 AM -
GUI with java.lang.IllegalStateException
By eckt in forum AWT / SwingReplies: 4Last Post: 06-14-2010, 11:32 AM -
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException:
By satishkumar_lskin in forum AWT / SwingReplies: 2Last Post: 12-14-2009, 02:46 AM -
java.lang.IllegalStateException: Cannot forward after response has been committed
By saran87 in forum New To JavaReplies: 13Last Post: 09-07-2009, 05:32 PM -
whether this will throw 'InterruptedException' or 'IllegalStateException'
By vysh in forum New To JavaReplies: 2Last Post: 05-28-2009, 06:09 PM
Bookmarks