I'm making a Chain Rxn clone and after playing the game for a while it gives me this:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at sun.audio.AudioStream.getData(AudioStream.java:90)
at grid.Dot.playSound(Dot.java:314)
at grid.Dot.explode(Dot.java:163)
at grid.Grid.play(Grid.java:166)
at grid.Grid.init(Grid.java:116)
at chainrxnalpha.chainrxnalpha.main(chainrxnalpha.jav a:68))
This is the method where the error is thrown:
public void playSound(String soundFile) { try { SFX = new AudioStream(new FileInputStream("src/sounds/" + soundFile + ".wav")); MD = SFX.getData(); // this is where the error (in red above^^) is thrown once = new AudioDataStream(MD); } catch (IOException error) { System.out.println("File not found!"); } MGP.start(once); // sometimes the error is thrown here depending on the frequency of sounds playing try { SFX.close(); } catch (IOException error) { System.out.println("Closing error"); } System.out.println("play sound " + soundFile); }
I have deduced that the error has to do with the inefficiency of data being transferred, but should not Java have this stuff done automatically? Or is there a different way to play sound that I am unaware of?
I have already tried to increase heap size with a Plist editor but I still get the same error at the same time.
I am on an iMac and using Netbeans 6.7.1 (I get the same error on the school computers which are PCs).
Ask me for more info if this is not clear. thankyooo