So I was following Travis's android tutorials and he was giving an example of a HTTP Client

I copied his code as it was but mine doesn't work


package com.quara.monk;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;

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;

public class HTTPExample {
public String getInternetData() throws Exception {
BufferedReader in = null;
String data = "";

try {
HttpClient client = new DefaultHttpClient();
URI website = new URI("https://www.mybringback.com/");
HttpGet request = new HttpGet();
request.setURI(website);
HttpResponse response = client.execute(request);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String l = "";
String nl = System.getProperty("line.separator");
while((l = in.readLine()) != null) {
sb.append(l + nl);
}
in.close();
data = sb.toString();
return data;
} finally {
if(in != null) {
try{
in.close();
return data;
} catch(Exception e) {
e.printStackTrace();
}
}
}
}
}



// MAIN ACTIVITY


package com.quara.monk;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView httpstuff = (TextView) findViewById(R.id.textView1);
HTTPExample test = new HTTPExample();
String returned;
try {
returned = test.getInternetData();
httpstuff.setText(returned);
} catch(Exception e) {
e.printStackTrace();
httpstuff.setText("fadsfadsfadsfasfadfaf");
}

}
}

the getInternetData() Method throws some exception. Any idea why.

and I'm using android 4.0. Does this make any difference because travis was using 2.1. Or maybe I have to add some permission. I did add the Internet one but that didn't make any difference...