获取Java异常:java.net.MalformedURLException:无协议
时间:2020-03-05 18:52:29 来源:igfitidea点击:
我目前正在调用以下代码行:
java.net.URL connection_url = new java.net.URL("http://<ip address>:<port>/path");
并且执行时出现上述异常。有什么想法为什么会这样?
解决方案
回答
附带说明,我们应该使用URI,因为Java URL类搞砸了。 (我相信等于方法)
回答
该网址字符串看起来无效。确定不应该是'http:// path'吗?还是服务器和端口为空?
回答
代码对我来说非常合适:
public static void main(String[] args) { try { java.net.URL connection_url = new java.net.URL("http://:/path"); System.out.println("Instantiated new URL: " + connection_url); } catch (MalformedURLException e) { e.printStackTrace(); } }
Instantiated new URL: http://:/path
确定代码正确吗?