Issue
I want to get html from web but I can't. here is my code
final EditText et = (EditText) findViewById(R.id.editText1);
final TextView tv = (TextView) findViewById(R.id.textView1);
final Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
URL url = null;
url = new URL(et.getText().toString());
URLConnection conn = url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
tv.append(line);
}
} catch (Exception e) {
Log.e("error", "erorr connection "+ e.toString());
}
}
});
I also add permission from internet already. Target version 4.0.3
Solution
Please put network parts into background thread then update to foreground UI thread. You can use AsyncTask to do so.
Answered By - sam.wang.0723
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.