So, first off, here is my code:
public class MainActivity extends Activity {
Button refresh;
TextView login;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
login = (TextView) findViewById(R.id.tvLogin);
GetMethod test = new GetMethod();
String returned;
try{
returned = test.getInternetData();
login.setText(returned);
}catch(Exception e){
e.printStackTrace();
}
}
}
That's my MainActivity in my Android app. Here is GetMethod.
public class GetMethod {
public String getInternetData() throws Exception{
BufferedReader in = null;
String data = null;
try{
HttpClient client = new DefaultHttpClient();
URI website = new URI("https://www.google.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();
}
}
}
}
}
I'm not getting errors and I don't see anything wrong, but I'm tired and if this is simple, I'm sorry. I've been fiddling with it forever. I've found the code on test.getInternetData()is givind an exception.
EDIT:Clarification, it's not getting to the code login.setText(returned);