0

Hi i need your help please I am still learning android...i don't know this error "at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1133)"...
can you help me how to solve this.

Thank you.

3
Contributors
6
Replies
16
Views
4 Years
Discussion Span
Last Post by peter_budo
0
public void onClick(View arg0){


   try{


       HttpClient httpclient = new DefaultHttpClient();
       nameValuePairs = new ArrayList<NameValuePair>(2);
       nameValuePairs.add(new BasicNameValuePair("username",username.getText().toString()));
       nameValuePairs.add(new BasicNameValuePair("password",password.getText().toString()));

       HttpPost  httppost = new HttpPost("http://10.0.2.2:8080/myandroid/add.php");


       httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
       HttpResponse response = httpclient.execute(httppost);


   }
   catch(IOException ex){
       System.out.print(ex.getMessage());
   }

    Toast  toast = Toast.makeText(this, username.getText()+" "+password.getText(), Toast.LENGTH_SHORT);
    toast.show();

}

Edited by peter_budo: Fixing code formatting

0

Hi peter budo,Thank you for the reply...can i ask how did you know that i am performing in the UI thread...I do apologize i am still learning android.

0

To respond to your previous question answer is simple. onClick() event have to be associated with listener that has to be attached to UI element that can only exist in View, Fragment or Activity

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.