每当我尝试音频剪辑时,我都会收到这样的错误:
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);
}
}
}发布于 2014-01-21 08:50:19
URL必须以类似http://..或file://..之类的内容开头。显示的URL不是,它不是有效的URL。
发布于 2014-01-21 08:50:58
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)
https://stackoverflow.com/questions/21247091
复制相似问题