Hallo,
Der folgende Code verursacht bei mir die Fehlermeldung
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
Aber erst nach mehrmaligen ausführen.
musik ist eine boolean die immer umgestellt wird (mit m für mute)
Java:
try{if(musik){int rand =(int)(5*Math.random()+1);System.out.println(rand);AudioInputStream audioInputStream =AudioSystem.getAudioInputStream(newFile(Sounds+"Musik"+ rand +".wav").getAbsoluteFile());
clip =AudioSystem.getClip();
clip.open(audioInputStream);
clip.loop(Clip.LOOP_CONTINUOUSLY);
audioInputStream.close();}else{
clip.stop();}}catch(Exception ex){System.out.println("Error with playing sound.");
ex.printStackTrace();}
Ich habe keine Ahnung warum es diesen Fahler hat und dadurch auch nicht wie er zu beheben ist...
Ich danke für alle Hilfe!
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
at com.sun.media.sound.DirectAudioDevice$DirectClip.open(Unknown Source)
at aMazeIng.aMazeIng$2.Musik(aMazeIng.java:912)
at aMazeIng.aMazeIng$2.keyPressed(aMazeIng.java:550)
at java.awt.Component.processKeyEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Window.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
Die Ausgabe der 1. Zeile sagt es ja schon: Out of Memory. Oder zu deutsch, Arbeitsspeicher der der JRE zur verfügung stehen ist aufgebraucht. Führst du das Programm denn mehrmals parallel aus oder wird dieser Codebereich mehrmals aufgerufen?
man stellt durch drücken der taste m die boolean musik um und danach wird dies aufgerufen.
Keine parallelen Programme.
Anscheinend verbraucht die Musik aber weiterhin Speicher...