[英]getting java exception: java.net.MalformedURLException: no protocol
I am currently calling the following line of code: 我目前正在调用以下代码行:
java.net.URL connection_url = new java.net.URL("http://<ip address>:<port>/path");
and I get the exception above when it executes. 我执行时得到上面的异常。 Any ideas as to why this is happening?
关于为什么会发生这种情况的任何想法?
That url string looks like it's invalid. 该url字符串看起来像是无效的。 Sure it's not supposed to be ' http://path '?
当然它不应该是' http:// path '? Or are the server & port blank?
或者服务器和端口是空白的?
Your code works perfectly fine for me: 你的代码对我来说非常好:
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
实例化的新URL: http://:/ path
Sure you have the right line of code? 当然你有正确的代码行?
I had the same error and it got resolved by the below : 我有同样的错误,它由以下解决:
The jar files (JFree) which I added few days back got corrupted automatically and was causing this error. 几天前我添加的jar文件(JFree)自动损坏并导致此错误。 I downloaded the same files again from net and it worked fine for me.
我再次从网上下载了相同的文件,它对我来说很好。
I have also had the same exception, but in my case the URL which I was trying to execute had a space appended. 我也有同样的例外,但在我的情况下,我试图执行的URL附加了一个空格。 After removing the space it worked fine for me.
删除空间后,它对我来说很好。 Check that the URL does not have any trailing spaces in your case.
在您的情况下检查URL没有任何尾随空格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.