我有下一个课程,它存储了我将用于游戏的所有声音,但是我试图测试Jar文件以查看是否正常工作我从命令提示符
中找到了下一个错误 Exception in thread "main" java.lang.NullPointerException
at com.sun.media.sound.StandardMidiFileReader.getSequence(Unknown Source)
at javax.sound.midi.MidiSystem.getSequence(Unknown Source)
at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unknown Source)
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at Assets.AudioStreaming.loadMusicAssets(AudioStreaming.java:27)
at CrossyMain.MainMenu.<init>(MainMenu.java:64)
at CrossyMain.Principal.main(Principal.java:18)
这是我存储所有音频资产的课程
package Assets;
import java.io.IOException;
import javax.sound.sampled.*;
public class AudioStreaming {
private static Clip mainMenu,BGM,coinP,gameOver,trainAlert,birdGO;
private static AudioInputStream in_mainMenu,in_BGM,in_coinP,in_gameOver,in_trainAlert,in_birdGO;
public static void loadMusicAssets(){
try{
/*Background*/
BGM = AudioSystem.getClip();
in_BGM = AudioSystem.getAudioInputStream(AudioStreaming.class.getResource("/sound/background/NeonW.wav"));
BGM.open(in_BGM);
coinP = AudioSystem.getClip();
in_coinP = AudioSystem.getAudioInputStream(AudioStreaming.class.getResource("/sound/entityFx/coinPickup.wav"));
coinP.open(in_coinP);
gameOver = AudioSystem.getClip();
in_gameOver = AudioSystem.getAudioInputStream(AudioStreaming.class.getResource("/sound/entityFx/gameOver.wav"));
gameOver.open(in_gameOver);
trainAlert = AudioSystem.getClip();
in_trainAlert = AudioSystem.getAudioInputStream(AudioStreaming.class.getResource("/sound/entityFx/trainWarning.wav"));
trainAlert.open(in_trainAlert);
birdGO = AudioSystem.getClip();
in_birdGO = AudioSystem.getAudioInputStream(AudioStreaming.class.getResource("/sound/entityFx/eaglePickup.wav"));
birdGO.open(in_birdGO);
mainMenu = AudioSystem.getClip();
in_mainMenu = AudioSystem.getAudioInputStream(AudioStreaming.class.getResource("/sound/background/NeonValley.wav"));
mainMenu.open(in_mainMenu);
}catch(LineUnavailableException | UnsupportedAudioFileException | IOException e){
e.printStackTrace();
}
}
public static void playBGM(){
BGM.setFramePosition(0);
BGM.start();
}
public static void stopBGM(){
BGM.stop();
BGM.close();
}
public static void playMainMenu(){
mainMenu.setFramePosition(0);
mainMenu.start();
}
public static void stopMainMenu(){
mainMenu.stop();
mainMenu.close();
}
public static void playTrainWarning(){
trainAlert.setFramePosition(0);
trainAlert.start();
}
public static void stopTrainWarning(){
trainAlert.stop();
trainAlert.close();
}
public static void playBirdGO(){
birdGO.setFramePosition(0);
birdGO.start();
}
public static void playCoinP(){
coinP.setFramePosition(0);
coinP.start();
}
public static void playGameOver(){
gameOver.setFramePosition(0);
gameOver.start();
}
}
它在NetBeans中完美运行,没有任何错误,但是它成功编译了JAR文件,但是我注意到命令提示符出现这个错误,因为它不想通过双击打开它?有没有人遇到过这个错误?如果是这样,你是如何设法将声音资产加载到Jar文件的?任何提示/建议将非常感谢您的时间!