我用Java做了一个游戏。虽然在eclipse中它可以正常工作,但是当打包到jar中时,映射中的对象永远不会被销毁。为了检查是否有任何异常,我从命令行启动了它,并且java向我说明了以下例外情况。
C:\Users\SriHarshaCH>java -jar C:\Users\SriHarshaCH\Desktop\Treasure.jar
java.io.IOException: mark/reset not supported
at java.util.zip.InflaterInputStream.reset(Unknown Source)
at java.io.FilterInputStream.reset(Unknown Source)
at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unknown Source)
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at com.gej.sound.WavPlayer.loadSound(WavPlayer.java:39)
at treasure.Treasure.initResources(Treasure.java:152)
at com.gej.core.Game.run(Game.java:117)
at java.lang.Thread.run(Unknown Source)
java.io.IOException: mark/reset not supported
at java.util.zip.InflaterInputStream.reset(Unknown Source)
at java.io.FilterInputStream.reset(Unknown Source)
at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unknown Source)
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at com.gej.sound.WavPlayer.loadSound(WavPlayer.java:39)
at treasure.Treasure.initResources(Treasure.java:154)
at com.gej.core.Game.run(Game.java:117)
at java.lang.Thread.run(Unknown Source)
java.io.IOException: mark/reset not supported
at java.util.zip.InflaterInputStream.reset(Unknown Source)
at java.io.FilterInputStream.reset(Unknown Source)
at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unknown Source)
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at com.gej.sound.WavPlayer.loadSound(WavPlayer.java:39)
at treasure.Treasure.initResources(Treasure.java:156)
at com.gej.core.Game.run(Game.java:117)
at java.lang.Thread.run(Unknown Source)
java.io.IOException: mark/reset not supported
at java.util.zip.InflaterInputStream.reset(Unknown Source)
at java.io.FilterInputStream.reset(Unknown Source)
at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unknown Source)
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at com.gej.sound.WavPlayer.loadSound(WavPlayer.java:39)
at treasure.Treasure.initResources(Treasure.java:158)
at com.gej.core.Game.run(Game.java:117)
at java.lang.Thread.run(Unknown Source)
java.io.IOException: mark/reset not supported
at java.util.zip.InflaterInputStream.reset(Unknown Source)
at java.io.FilterInputStream.reset(Unknown Source)
at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unknown Source)
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at com.gej.sound.WavPlayer.loadSound(WavPlayer.java:39)
at treasure.Treasure.initResources(Treasure.java:163)
at com.gej.core.Game.run(Game.java:117)
at java.lang.Thread.run(Unknown Source)但我没有使用任何zip文件,wav-player在游戏中也能正常工作。游戏仍然启动。但是这些对象不会从地图上移除。我怎么能解决这个?
这里是更新和删除死对象的地图的updateobjects方法。
/**
* Updates all the objects contained in the map.
* @param elapsedTime The time elapsed in the current frame.
*/
public static void updateObjects(long elapsedTime){
for (int i=0; i
try {
GObject obj = objects.get(i);
if (obj!=null){
if (obj.isAlive()){
obj.superUpdate(elapsedTime);
obj.moveHorizontally(elapsedTime);
checkCollisions(obj, true, false);
obj.moveVertically(elapsedTime);
checkCollisions(obj, false, true);
checkCollisions(obj, false, false);
} else {
// Remove the dead object
objects.remove(i);
}
} else {
objects.remove(i);
}
} catch (NullPointerException e){}
}
}编辑:当jar被提取并且用代码启动时,游戏运行良好
java treasure.Treasure它什么都没有返回并且发挥出色
这里是loadSound方法
/**
* Loads a sound from a file in the jar file to play them
* at any time. Supports loading of .wav, .au, .aiff files.
* Also converts MIDI files on the fly
* @param s The path of the wav file.
* @return The sound data loaded into the WavSound object
*/
public static WavSound loadSound(String s){
// Get an input stream
InputStream is = WavPlayer.class.getClassLoader().getResourceAsStream(s);
AudioInputStream audioStream;
try {
// Create the audio input stream and audio format
audioStream = AudioSystem.getAudioInputStream(is);
AudioFormat format = audioStream.getFormat();
// The length of the audio file
int length = (int)(audioStream.getFrameLength() * format.getFrameSize());
// The array to store the samples in
byte[] samples = new byte[length];
// Read the samples into array to reduce disk access (fast-execution)
DataInputStream dis = new DataInputStream(audioStream);
dis.readFully(samples);
// Create a sound container
WavSound sound = new WavSound(samples, format);
// Don't start the sound on load
sound.setState(SoundState.STATE_STOPPED);
// Create a new player for each sound
new WavPlayer(sound);
return sound;
} catch (Exception e){
// An error. Mustn't happen
e.printStackTrace();
}
return null;
}现在重新创建jar文件修复了异常问题。但是物体没有被破坏。