所以我正在开发一个浏览器(只是因为),我不断得到一个java.net.MalformedURLException
. 我正在尝试将 aJEditorPane
的页面设置为从我的计算机加载的文件。这是代码:
public Browser() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500, 500);
URLField = new JTextField("Enter the full address of the website:");
displayWindow = new JEditorPane();
try {
homeURL = new URL(getCurrentDirectory() + "/resources/home.html");
displayWindow.setPage(homeURL);
} catch (IOException e) {
e.printStackTrace();
}
tabs = new JTabbedPane();
tabs.addTab("Home", displayWindow);
add(URLField, BorderLayout.PAGE_START);
add(displayWindow, BorderLayout.CENTER);
}
这是我得到的错误:
java.net.MalformedURLException: unknown protocol: x
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at net.sourceforge.whowantsakookie.browser.Browser.<init>(Browser.java:25)
at net.sourceforge.whowantsakookie.browser.Browser.main(Browser.java:42)
它所指的行是第 25 行和第 42
行。第 25 行:
homeURL = new URL(getCurrentDirectory() + "/resources/home.html");
第 42 行:
Browser browser = new Browser();
提前致谢!