So i am following the lynda course on android development and after following the URL connection tutorial, for some reason the instructor's code produces results but mine does not. here are the files that i have
Main.java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Main extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText et = (EditText) findViewById(R.id.editText1);
Button pressMe= (Button) findViewById(R.id.button1);
final TextView tv = (TextView) findViewById(R.id.textView1);
pressMe.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
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){
}
}
});
}
}
i have checked my code and compared it with the instructors. i have also checked online to see if the URL connection method is still valid and after research it is still valid. I have dont another tutorial using HTTpClient and i have gotten results from that. However for learning purposes i would like to see if URL connection works. I do hae the internet permission enbaled in my Android_manifest file. Thank you for the help.