Исключение звука JavaJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Исключение звука Java

Сообщение Anonymous »

Итак, после того, как я научился создавать работающий работоспособный файл .jar и после некоторых тестов,
я начал менять свою программу, чтобы я мог создавать файл .jar, но основная проблема заключается в том, что после некоторых изменений программа может не воспроизвожу аудиофайлы.
Я переместил аудиофайлы в исходный каталог следующим образом:

Код: Выделить всё

ROOT
|
|--src
|   | -- com.game.main...  etc
|
|--userdata
|
|--resources
|   |-- res
| -- sound
|--sound.wav

Эта логика работает, и я могу создать файл .jar
Когда я запускаю его в eclipse, он выдает исключения:

Код: Выделить всё

java.lang.NullPointerException: Cannot invoke "javax.sound.sampled.Clip.start()" because "this.this$0.clip" is null
at aGame.v2/com.game.lib.entity.Entity$SoundPlayer.run(Entity.java:92)
java.lang.NullPointerException: Cannot invoke "javax.sound.sampled.Clip.start()" because "this.this$0.clip" is null
at aGame.v2/com.game.lib.entity.Entity$SoundPlayer.run(Entity.java:92)
java.lang.NullPointerException: Cannot invoke "javax.sound.sampled.Clip.start()" because "this.this$0.clip" is null
at aGame.v2/com.game.lib.entity.Entity$SoundPlayer.run(Entity.java:92)
java.lang.NullPointerException: Cannot invoke "javax.sound.sampled.Clip.start()" because "this.this$0.clip" is null
at aGame.v2/com.game.lib.entity.Entity$SoundPlayer.run(Entity.java:92)
java.lang.NullPointerException: Cannot invoke "javax.sound.sampled.Clip.start()" because "this.this$0.clip" is null
at aGame.v2/com.game.lib.entity.Entity$SoundPlayer.run(Entity.java:92)
java.lang.NullPointerException: Cannot invoke "javax.sound.sampled.Clip.start()" because "this.this$0.clip" is null
at aGame.v2/com.game.lib.entity.Entity$SoundPlayer.run(Entity.java:92)
java.lang.NullPointerException: Cannot invoke "javax.sound.sampled.Clip.start()" because "this.this$0.clip" is null
at aGame.v2/com.game.lib.entity.Entity$SoundPlayer.run(Entity.java:92)
java.lang.NullPointerException: Cannot invoke "javax.sound.sampled.Clip.start()" because "this.this$0.clip" is null
at aGame.v2/com.game.lib.entity.Entity$SoundPlayer.run(Entity.java:92)
java.lang.NullPointerException: Cannot invoke "javax.sound.sampled.Clip.start()" because "this.this$0.clip" is null
at aGame.v2/com.game.lib.entity.Entity$SoundPlayer.run(Entity.java:92)
java.lang.NullPointerException: Cannot invoke "javax.sound.sampled.Clip.start()" because "this.this$0.clip" is null
at aGame.v2/com.game.lib.entity.Entity$SoundPlayer.run(Entity.java:92)
java.lang.NullPointerException: Cannot invoke "javax.sound.sampled.Clip.start()" because "this.this$0.clip"  is null
at aGame.v2/com.game.lib.entity.Entity$SoundPlayer.run(Entity.java:92)
И исключения:

Код: Выделить всё

javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 48000.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
at java.desktop/com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(DirectAudioDevice.java:484)
at java.desktop/com.sun.media.sound.DirectAudioDevice$DirectClip.implOpen(DirectAudioDevice.java:1238)
at java.desktop/com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:115)
at java.desktop/com.sun.media.sound.DirectAudioDevice$DirectClip.open(DirectAudioDevice.java:1038)
at java.desktop/com.sun.media.sound.DirectAudioDevice$DirectClip.open(DirectAudioDevice.java:1131)
at aGame.v2/com.game.lib.entity.Entity$SoundPlayer.run(Entity.java:83)
javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 48000.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
at java.desktop/com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(DirectAudioDevice.java:484)
at java.desktop/com.sun.media.sound.DirectAudioDevice$DirectClip.implOpen(DirectAudioDevice.java:1238)
at java.desktop/com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:115)
at java.desktop/com.sun.media.sound.DirectAudioDevice$DirectClip.open(DirectAudioDevice.java:1038)
at java.desktop/com.sun.media.sound.DirectAudioDevice$DirectClip.open(DirectAudioDevice.java:1131)
at aGame.v2/com.game.lib.entity.Entity$SoundPlayer.run(Entity.java:83)
Это код:

Код: Выделить всё

public abstract class Entity {
public int x, y;
public int width, height;
public Rectangle rect;

protected int hp;
protected int strength;
protected int kills;

public static final int GRAPHIC_BORDER = 6;
protected boolean drawMore;
protected Image image;
protected boolean damaged;

protected Context context;
protected Color entityColor;
protected GamePanel gp;
protected KeyHandler keyH;
protected Clip clip;

public Entity(Context x, Color ec) {
entityColor = ec;
context = x;
if (x!=null) {
keyH = x.keyH;
gp = x.gp;
}
damaged = false;
hp = 100;
kills = 0;

}

public synchronized void playSound (String path) {
try {
URL is = getClass().getResource(path);
//BufferedInputStream bis = new BufferedInputStream(is);
SoundPlayer sp = new SoundPlayer(is);
sp.start();
} catch (Exception e) {
e.printStackTrace();
}
}

class SoundPlayer extends Thread {
private URL soundFile;
public SoundPlayer (URL is) {
this.soundFile = is;
}
@Override
public void run () {
try {
if (clip!=null) {
//clip.stop();
clip.close();
}

clip = null;

AudioInputStream ais = AudioSystem.getAudioInputStream(soundFile);
clip = AudioSystem.getClip();
clip.open(ais);

clip.start();
} catch (Exception e) {
e.printStackTrace();
}

}
}
Может ли кто-нибудь помочь мне решить эту проблему?????

Подробнее здесь: https://stackoverflow.com/questions/793 ... excpeption
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»