每当我尝试音频片段时,都会收到此错误:
java.net.MalformedURLException: no protocol: /Users/videogames/Documents/workspace/TryApplets/res/adv.wav---------
有什么问题?这是程序的代码。 (我使用mac,如果这很重要的话)
package game;
import java.applet.*;
import java.net.*;
public class sound {
/**
* @param args
*/
public static void main(String[] args) {
try {
URL url = new URL("/Users/videogames/Documents/workspace/TryApplets/res/adv.wav");
AudioClip clip = Applet.newAudioClip(url);
clip.play();
} catch (MalformedURLException murle) {
System.out.println(murle);
}
}
}
答案 0 :(得分:2)
网址必须以http://..
或file://..
开头。显示的URL不是,它不是有效的URL。
答案 1 :(得分:2)
URL类的有效协议是
http, https, ftp, file, and jar
所以试试
URL url = new URL("file://Users/videogames/Documents/workspace/TryApplets/res/adv.wav");
如有疑问,请阅读API
http://docs.oracle.com/javase/7/docs/api/java/net/URL.html#URL(java.lang.String)