I using the below code to retrieve the data from the database. I am getting the error "android.os.NetworkOnMainThreadException".
public void select()
{
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("id",id));
try
{
Toast.makeText(getApplicationContext(), "inside try block",Toast.LENGTH_LONG).show();
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://129.107.239.106/select.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
Toast.makeText(getApplicationContext(), "entity ",Toast.LENGTH_LONG).show();
is = entity.getContent();
Log.e("pass 1", "connection success ");
}
catch(Exception e)
{
Log.e("Fail 1", e.toString());
Toast.makeText(getApplicationContext(), e.toString(),Toast.LENGTH_LONG).show();
} }
I have provided permission code to access internet in Manifest file. Could someone please help me with this error. Thanks in advance.