【发布时间】:2016-08-08 07:21:28
【问题描述】:
public static synchronized void playSound(final String url) {
new Thread(new Runnable() {
// The wrapper thread is unnecessary, unless it blocks on the
// Clip finishing; see comments.
public void run() {
try {
Clip clip = AudioSystem.getClip();
AudioInputStream inputStream = AudioSystem.getAudioInputStream(
Main.class.getResourceAsStream("Draco-s-Pong-master\\demo\\Sounds" + url));
clip.open(inputStream);
clip.start();
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}).start();
playSound("Draco Background.wav");
}
我查看了来自其他线程的几十个代码,它们都给我 null 并继续发送垃圾邮件,直到我关闭程序。我在 Sounds 文件夹中有那个 .wav 文件,我什至将它放在项目中的任何地方,它每次仍然给我null。我想要它作为简单的背景。
【问题讨论】:
-
Main.class.getResourceAsStream("Draco-s-Pong-master\\demo\\Sounds" + url)) 更改为 Main.class.getResourceAsStream("//声音" + url))
-
能不能简单解释一下,我的classpath下的文件夹是什么意思,怎么理解我的classpath?
-
类路径是文件结构的根目录,默认包的文件夹。见link
-
我还是不太明白,如何查看我的classpath?