button组件设置 onClick=“click”
public void click(View v){
String path=et.getText().toString().trim();
try {
URL url=new URL(path);
HttpURLConnection con=(HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setConnectTimeout(5000);
int code=con.getResponseCode();
if(code==200){
InputStream ins=con.getInputStream();
String content=StreamTools.readStream(ins);
tv.setText(content);
}
} catch (Exception e) {
}
从et获取网址,加了android.permission.INTERNET权限
调试运行发现,执行到con.getResponseCode()就抛出异常,把这行注释掉后面的con.getInputStream() 依旧抛出异常
请问是什么原因