定义了一个按钮btn 的onClick=“click”
ublic class MainActivity extends Activity {
private EditText et;
private TextView tv;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et = (EditText) findViewById(R.id.et);
tv = (TextView) findViewById(R.id.btn);
}
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) {
}
}
}
从editView组件获取网址,然后程序执行到 int code=con.getResponseCode();
这行就不动了,把这行删掉,执行 InputStream ins=con.getInputStream();这行也是没有反应。已经添加了android.permission.INTERNET权限,请问是什么原因