我在我的mac上创建了一个tictactoe(creategame class)游戏,上传到GitHub,在windows 7上下载。然后在运行eclipse项目时出现这个错误。在研究中,我认为这是一个软件/驱动程序问题,或者它没有检测到声音文件,作为一个初学者,我完全被难住了。谢谢大家帮助。
> Error with playing sound.
java.lang.NullPointerException
at javax.sound.sampled.AudioSystem.getDefaultMixer(Unknown Source)
at javax.sound.sampled.AudioSystem.getLine(Unknown Source)
at TicTacToe.CreateGame.playSound(CreateGame.java:144)
at TicTacToe.CreateGame.actionPerformed(CreateGame.java:194)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
public void playSound() {
// Load sounds
try {
AudioInputStream A = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("/A3_04.wav"));
AudioInputStream Bb = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("/Bb4_01.wav"));
AudioInputStream C = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("/C5_01.wav"));
AudioInputStream D = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("/D4_01.wav"));
AudioInputStream E = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("/E4_01.wav"));
AudioInputStream F = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("/F4_01.wav"));
AudioInputStream G = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("/G4_01.wav"));
// IR and IR2 = random number max 7
AudioInputStream[] Sounds = { C, D, E, F, G, A, Bb };
Clip clip = AudioSystem.getClip();
Clip clip2 = AudioSystem.getClip();
clip.open(Sounds[IR]);
clip2.open(Sounds[IR2]);
clip.start();
clip2.start();
} catch (Exception ex) {
System.out.println("Error with playing sound.");
ex.printStackTrace();
}
}
非常感谢您的帮助:P