The method openConnection() is undefined for the type URI

sky_sea_desert_me 2016-10-23 01:20:29
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLConnection;
public class UrlImage {
public static void main(String[] args) {
String str="http://www.icon.nipic.com/BannerPic/20161008/home/20161008145324.jpg";
try {
URI url=new URI("http://icon.nipic.com/BannerPic/20161008/home/20161008145324.jpg");
URLConnection connection=url.openConnection();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}
报错如下:The method openConnection() is undefined for the type URI
谢谢了。我查看了api 与别人写的文档,都可以啊
...全文
215 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
lerry1245 2020-09-01
  • 打赏
  • 举报
回复 1
应该定义是URL而不是URI,URI接口下面没有 openConnection()方法

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧