删除未使用 java_java中未使用的异常以及从地图中删除对象

我用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文件修复了异常问题。但是物体没有被破坏。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值