I have tried to use an instance of BufferReader to read a content of a web page but when running the app, it moves immediately to catch block when reaching this line:
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
Could you please tell me what is the problem? By the way, I have made a permmition to Internet connection in the mainifest file and there is no error registered in the Log cat! this is my java code:
Thread thrd = new Thread( new Runnable() {
@Override
public void run() {
final Button btn = (Button) findViewById(R.id.btn_1);
final TextView tv = (TextView) findViewById(R.id.tv_1);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
URL url = null;
url = new URL("http://www.google.com/");
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){
tv.append("There is a problem");
}
}
});
}
});
thrd.start();
return true;
}