以下のコードを使用して、データベースからデータを取得します。「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();
} }
マニフェストファイルでインターネットにアクセスするための許可コードを提供しました。誰かがこのエラーを手伝ってくれませんか。前もって感謝します。