我正在制作一个程序,它使用 PHP 页面连接到数据库,然后通过 JSON 解析信息。问题是,我在负责网络通信的 AsyncTask 上得到了一个 RuntimeException。我正在使用物理 android 设备进行测试。
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("URL");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("password", "******"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Error appears on this line
HttpResponse response = httpclient.execute(httppost);
//JSON Parsing here
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
catch (Throwable t)
{
CharSequence message = "Request failed: " + t.toString();
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
}