リクエストを実行してレスポンスを非同期タスクとして返そうとしています。 。非同期のAsyncTaskとして実行リクエストでAndroid HttpClientがクラッシュする
public class HttpUtilz{
HttpGet getRequest;
public NodeList executeGetAndReceiveNodeList(String url, String xpath)throws XPathExpressionException,IOException,ParserConfigurationException,SAXException{
getRequest=new HttpGet(url);
HttpResponse response = (HttpResponse) new RetrieveAsyncResp().execute(getRequest);
InputStream inputStream = response.getEntity().getContent();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document doc = builder.parse(inputStream);
doc.getDocumentElement().normalize();
XPathFactory xPathFactory = XPathFactory.newInstance();
XPath xPath=xPathFactory.newXPath();
XPathExpression xPathExpression = xPath.compile(xpath);
return (NodeList)xPathExpression.evaluate(doc, XPathConstants.NODESET);
}
}
実装::私は「
public class RetrieveAsyncResp extends AsyncTask<HttpGet, String, HttpResponse> {
@Override
protected void onPreExecute(){
super.onPreExecute();
}
@Override
protected HttpResponse doInBackground(HttpGet... get) {
HttpClient client = new DefaultHttpClient();
HttpResponse response;
try {
response = client.execute(get[0]);
}catch (IOException e){
e.printStackTrace();
response=null;
}
return response;
}
@Override
protected void onPostExecute(HttpResponse response){
super.onPostExecute(response);
}
}
は、残念ながら、それは例外:( を引くことなく、クラッシュしたここで非同期を呼び出すコードクラスです次のテストに合格する: String url = "http://new-rutor.org/search/batman%20v%20superman"; 文字列xpath = "// div [@ id = 'インデックス']/table/tbody/tr/td [2]/a [2]";エミュレータが私を提供
唯一のものは、次のとおりです。
04-07 15:49:21.796 8396-8396/torrentz.com.torrentforme D/OpenGLRenderer﹕ Enabling debug mode 0
04-07 15:49:33.016 8396-8396/torrentz.com.torrentforme D/AndroidRuntime﹕ Shutting down VM
04-07 15:49:33.016 8396-8396/torrentz.com.torrentforme W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa4d6eb20)
私はあなたが非同期タスクのスケジュールを設定した後response
権利を読んで取得しようとしている任意のヘルプ/提案
クラッシュレポートを追加します。 –
AsyncTaskの使用を中止してください。それらは単なる苦痛の世界です。 – Bootstrapper
@RohitArya私はそうしたいと思っていますが、Bluestacksエミュレータを使用してこれを私に提供します:04-07 15:49:21.796 8396-8396/torrentz.com.torrentforme D/OpenGLRenderer:デバッグモードを有効にする0 04-07 15: 49:33.016 8396-8396/torrentz.com.torrentforme D/AndroidRuntime:VMをシャットダウンする 04-07 15:49:33.016 8396-8396/torrentz.com.torrentforme dalvikvm:threadid = 1:キャッチされていない例外でスレッドが終了する(group = 0xa4d6eb20) – Hunkeone