这样直接new的错误我也有过,象这样的类,它会丢出一个违例(Exception)所以一定要将它放在一个 try{}catch(){}块里象下面这样就可以了
try {
URL url = new String("https://mywebserver/mypage.htm");
}catch(MalformedURLException e) {
e.printStrackTrace();
}
try {
URL url = new String("https://mywebserver/mypage.htm");
}catch(MalformedURLException e) {
e.printStrackTrace();
}
1,URL能用String(xxxxx)去构造吗,应是
URL url=new URL(String);
2.需要捕获异常
请试试
URL url = new URL("https://mywebserver/mypage.htm"),运行错误,但我试过了
URL url = new URL("http://mywebserver/mypage.htm")是可以的。关键在与URL中的https and http 协议,java并不都支持。有什么方法可以生成https的URL.
也许对你有用
去看看吧
我也正为这事犯愁呢