我尝试将列表发送到服务器并使用此列表在数据库中搜索并创建响应并回复客户端但是当我运行程序时它停止。有时它会起作用,直到我停止它。经常项目停止在这一行
HttpResponse response = httpclient.execute(httppost);
在调试窗口中显示这个...
Thread [<15> AsyncTask #3] (Suspended (exception RuntimeException))
ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker) line: 1094
ThreadPoolExecutor$Worker.run() line: 569
代码:
public void onclick_search(View v)
{
dialog = ProgressDialog.show(this, "Sending...", "please wait...",true);
new Thread(new Runnable() {
@Override
public void run() {
postData();
}
}).start();
}
public void postData() {
String str = null;
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://saynaco.ir/Handler.ashx");
try {
List<NameValuePair> item_select = new ArrayList<NameValuePair>(6);
item_select.add(new BasicNameValuePair("land","sale" ));
item_select.add(new BasicNameValuePair("city", city ));
item_select.add(new BasicNameValuePair("price",s11 ));
item_select.add(new BasicNameValuePair("bar",s22));
item_select.add(new BasicNameValuePair("area",s33));
item_select.add(new BasicNameValuePair("land_kind", rb));
httppost.setEntity(new UrlEncodedFormEntity(item_select));
HttpResponse response = httpclient.execute(httppost);
str = inputStreamToString(response.getEntity().getContent()).toString();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
String []respon = str.split("&");
if(respon[0] == "ok")
{
dialog.dismiss();
Intent in = new Intent(getApplication(), List_show.class).putExtra("url", respon[1]);
startActivity(in);
Toast.makeText(getBaseContext(),"",Toast.LENGTH_SHORT).show();
//Intent in= new Intent(getBaseContext(), .class);
//startActivity(in);
}
else {
dialog.dismiss();
}
}
private StringBuilder inputStreamToString(InputStream is) {
String line = "";
StringBuilder total = new StringBuilder();
// Wrap a BufferedReader around the InputStream
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
// Read response until the end
try {
while ((line = rd.readLine()) != null) {
total.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
// Return full string
return total;
}