在尝试调用Web服务并获取相应的json对象时,我得到一个致命异常。我完全不知道在哪里看,以及要纠正哪些错误。获取“致命异常:AsyncTask#2”。我不知道是什么原因造成的
编辑:
private class CallServiceTask extends AsyncTask<Object, Void, JSONObject>
{
protected JSONObject doInBackground(Object... params)
{
HttpGet req = (HttpGet) params[0];
String url = (String) params[1];
return executeRequest(req, url);
}
}
而这里的所谓在doInBackground executeRequest方法:
private JSONObject executeRequest(HttpGet request, String url)
{
HttpClient client = new DefaultHttpClient();
JSONObject jsonObj = null;
client = getNewHttpClient();
HttpResponse httpResponse;
try {
httpResponse = client.execute(request);
HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
String response = convertStreamToString(instream);
try {
jsonObj = new JSONObject(response);
} catch (JSONException e1) {
e1.printStackTrace();
}
// Closing the input stream will trigger connection release
instream.close();
}
} catch (ClientProtocolException e) {
client.getConnectionManager().shutdown();
e.printStackTrace();
} catch (IOException e) {
client.getConnectionManager().shutdown();
e.printStackTrace();
}
return jsonObj;
}
问题是一类投放问题。你可以在你的asynctask中的'doInBackground'方法中发布代码。谢谢 – 2012-02-10 13:34:14
我认为你放错了代码。将代码粘贴到您称为CallServiceTask.excecute(...)的地方;来自RestClient.java。为了帮助我们需要RestClient.java – 2012-02-10 14:01:13