HTTPGET
特別に TIMEOUT 処理を使用し、応答トラフHttpResponse
とパストxmlR.parse(new InputSource(instream));
を取得して残りの手順を作成すると、解析で問題が発生しました。しかし、スローエラーがあります:
05-08 11:03:38.637: WARN/System.err(522): java.io.IOException: Attempted read on closed stream.
05-08 11:03:38.667: WARN/System.err(522): at org.apache.http.conn.EofSensorInputStream.isReadAllowed(EofSensorInputStream.java:127)
05-08 11:03:38.667: WARN/System.err(522): at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:176)
05-08 11:03:38.677: WARN/System.err(522): at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:515)
05-08 11:03:38.677: WARN/System.err(522): at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:478)
05-08 11:03:38.677: WARN/System.err(522): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:317)
05-08 11:03:38.677: WARN/System.err(522): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:275)
05-08 11:03:38.677: WARN/System.err(522): at com.housedisplay.mapspec.MyMapActivity.Sendsarchparameter(MyMapActivity.java:334)
05-08 11:03:38.687: WARN/System.err(522): at com.housedisplay.mapspec.MyMapActivity.access$0(MyMapActivity.java:289)
05-08 11:03:38.697: WARN/System.err(522): at com.housedisplay.mapspec.MyMapActivity$SearchATask.doInBackground(MyMapActivity.java:251)
05-08 11:03:38.697: WARN/System.err(522): at com.housedisplay.mapspec.MyMapActivity$SearchATask.doInBackground(MyMapActivity.java:1)
05-08 11:03:38.697: WARN/System.err(522): at android.os.AsyncTask$2.call(AsyncTask.java:252)
05-08 11:03:38.697: WARN/System.err(522): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
05-08 11:03:38.697: WARN/System.err(522): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-08 11:03:38.697: WARN/System.err(522): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
05-08 11:03:38.697: WARN/System.err(522): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
05-08 11:03:38.697: WARN/System.err(522): at java.lang.Thread.run(Thread.java:1020)
コード::
HttpGet httpGet = new HttpGet(strURL.toURI());
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.
// The default value is zero, that means the timeout is not used.
int timeoutConnection = 3000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 5000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpResponse response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
InputStream instream = entity.getContent();
if (entity != null) {
strResponse = convertStreamToString(instream);
}
/**********test*******/
SAXParserFactory saxPF = SAXParserFactory.newInstance();
SAXParser saxP = saxPF.newSAXParser();
XMLReader xmlR = saxP.getXMLReader();
System.out.println("url >>>>>" + strURL);
HandlerFromLatLongCustom myXMLHandler = new HandlerFromLatLongCustom();
xmlR.setContentHandler(myXMLHandler);
xmlR.parse(new InputSource(instream));
instream.close();