-2

I'm trying to receive data from remote server and insert the data to variable "respond" but the app crashes... I don't have log , because my emulator doesnt work, and sdk driver's for my phone also doesnt work, so I install the apk file via usb cable... the compiler doesn't show error. thanks for help

public class MainActivity extends Activity {

String serverURL = "http://www.adoninetwork.com/index.html";
String respond = "test";



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.activity_main);


    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(serverURL);

    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    try {
         respond = httpclient.execute(httppost, responseHandler);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    } 



    new AlertDialog.Builder(this).setMessage(respond).show();
CyanAngel
  • 1,240
  • 1
  • 14
  • 28
Alona
  • 27
  • 1
  • 8
  • To get logs via usb cable, use the command `adb logcat`. That should get you your error. – Andrew Schuster Jul 15 '14 at 14:34
  • possible duplicate of [android.os.NetworkOnMainThreadException](http://stackoverflow.com/questions/6343166/android-os-networkonmainthreadexception) – laalto Jul 17 '14 at 09:57

2 Answers2

1

You do a network connection on the Main Thread and Android don't allow that, so the system kill your app. You probably have the error NetworkOnMainThreadException

You have to use a AsyncTask (tutorial here) or the Google library Volley (documentation here).

Add your log if you want more explanation :)

AlonsoFloo
  • 505
  • 3
  • 10
0

check permission in manifest-

<uses-permission android:name="android.permission.INTERNET" />
Ratul Ghosh
  • 1,512
  • 9
  • 15