I found online that we can use HttpClient and HttpGet objects to download the source code of a page using java. But, whenever I try to do so, my IDE(Eclipse) asks me to surround some lines of code with a try/catch block and it won't compile unless I do so. But then again, when I surround those lines with a try/catch block some variables go out of scope raising another error. Here's what's happening -
package com.example.prs;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class PrsActivity extends Activity {
private TextView title;
private String url = "http://www.google.com";
private String pageHtml;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_prs); 
    title = (TextView) findViewById(R.id.title); 
    HttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet(url);
    HttpResponse response = client.execute(request); // asks to add try/catch block here
    String html = "";
    InputStream in = response.getEntity().getContent(); //asks to add try/catch block here
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    StringBuilder str = new StringBuilder();
    String line = null;
    while((line = reader.readLine()) != null)     // asks to add try/catch block here
    {
        str.append(line);
    }
    in.close(); // asks to add try/catch block here
    html = str.toString();
  }
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_prs, menu);
    return true;
    }
  }
and when I add the try/catch block, these errors show up -
package com.example.prs;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class PrsActivity extends Activity {
private TextView title;
private String url = "http://www.google.com";
private String pageHtml;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_prs); 
    title = (TextView) findViewById(R.id.title); 
    HttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet(url);
    HttpResponse response;
    try {
        response = client.execute(request);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    String html = "";
    InputStream in;
    try {
        in = response.getEntity().getContent();     //"response" goes out of scope
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    StringBuilder str = new StringBuilder();
    String line = null;
    try {
        while((line = reader.readLine()) != null)
        {
            str.append(line);
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        in.close();     //"in" goes out of scope
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    html = str.toString();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu`enter code here`.activity_prs, menu);
    return true;
   }
 }
Please help me to fix this problem. Thanks in advance.
 
     
    