解析器中引发IOException

时间:2012-07-02 15:57:15

标签: java android

我正在制作一个应用程序,我可以在其中调用webservices并填充数据。但这里由于一些奇怪的事情发生了。我的IOInception与arrayIndexoutofBound有错...我使用SAX解析器来解析简单的web服务。

错误::

07-02 16:50:52.992: E/NearbyScreen(31762): SAX PARSER ERRORjava.lang.ArrayIndexOutOfBoundsException: length=8192; regionStart=-2888; regionLength=11080
07-02 16:50:52.992: W/System.err(31762): java.lang.ArrayIndexOutOfBoundsException: length=8192; regionStart=-2888; regionLength=11080
07-02 16:50:53.002: E/NearbyScreen(31762): SAX PARSER ERRORjava.io.IOException: Attempted read on closed stream.
07-02 16:50:53.002: W/System.err(31762):    at java.util.Arrays.checkOffsetAndCount(Arrays.java:1731)
07-02 16:50:53.012: W/System.err(31762):    at java.net.PlainSocketImpl.read(PlainSocketImpl.java:484)
07-02 16:50:53.012: W/System.err(31762):    at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46)
07-02 16:50:53.012: W/System.err(31762):    at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240)
07-02 16:50:53.012: W/System.err(31762):    at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103)
07-02 16:50:53.012: W/System.err(31762):    at org.apache.http.impl.io.AbstractSessionInputBuffer.read(AbstractSessionInputBuffer.java:134)

code ::

DefaultHttpClient client = new DefaultHttpClient();
String ConcateURL = String.valueOf(newViewPortlatitude) + "," + String.valueOf(newViewPortlongitude)+"/TOUR/1000/1/5/";
URL URLPush = new URL(getString(R.string.NearbyURL)+ConcateURL);
                Log.i(TAG, "** URL ** ->" + URLPush);
                HttpGet httpGet = new HttpGet(URLPush.toURI());
                HttpParams httpParams = httpGet.getParams();
                int timeoutdConnection = 30000;
                HttpConnectionParams.setConnectionTimeout(httpParams,
                        timeoutdConnection);



                httpGet.setParams(httpParams);
                HttpResponse response = client.execute(httpGet);
                HttpEntity entity = response.getEntity();

                if (entity != null) {
                    Log.i("MyMapActivity", "--1--");
                    instream = entity.getContent();
                    Log.i("MyMapActivity", "--2--");
                }
                if (instream != null) {

                    Log.i("MyMapActivity", "--3--");

                    /********** test *******/
                    SAXParserFactory saxPF = SAXParserFactory.newInstance();
                    SAXParser saxP = saxPF.newSAXParser();
                    XMLReader xmlR = saxP.getXMLReader();
                    System.out.println("url >>>>>" + URLPush);
                    NearByHandler myXMLHandler = new NearByHandler();
                    xmlR.setContentHandler(myXMLHandler);
                    xmlR.parse(new InputSource(instream));
                    instream.close();

                    whaleWatchingInfoList = myXMLHandler.getQuotes();
                    // Fill Arraylist by Handler
                    Log.i(TAG, "whaleWatchingInfoList size "
                            + whaleWatchingInfoList.size());
                    Log.w("AndroidParseXMLActivity", "Done");
                }
            }catch (ConnectTimeoutException e) {
                Log.e(TAG, "ConnectionTimeOUT " + e);
                IsConnectionTimeoutException = true;
                //Flag ConnectionTimout
            }
            catch (Exception e) {
                Log.e(TAG, "SAX PARSER ERROR" + e);
                e.printStackTrace();

                //Flag ConnectionTimout
            }

更新

07-02 17:10:52.042: D/Process(1606): com.android.server.am.ActivityManagerService.serviceDoneExecuting(ActivityManagerService.java:12474)
07-02 17:10:52.042: D/Process(1606): android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:723)
07-02 17:10:52.042: D/Process(1606): com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:1714)
07-02 17:10:52.042: D/Process(1606): android.os.Binder.execTransact(Binder.java:338)
07-02 17:10:52.042: D/Process(1606): dalvik.system.NativeStart.run(Native Method)
07-02 17:10:53.643: D/WifiStateMachine(1606): fetchRssiAndLinkSpeedNative RSSI = -66
07-02 17:10:56.656: D/WifiStateMachine(1606): fetchRssiAndLinkSpeedNative RSSI = -65
07-02 17:10:59.669: D/WifiStateMachine(1606): fetchRssiAndLinkSpeedNative RSSI = -65
07-02 17:11:02.512: D/PhoneStatusBarPolicy(1695): silentresetvalue = 0, mTimerEnabled = false
07-02 17:11:02.512: D/PhoneStatusBarPolicy(1695): updateSignalStrength(), in service, remove timer
07-02 17:11:02.542: D/PhoneStatusBarPolicy(1695): isCdma():false hasService:true mSimState=UNKNOWN gprsState=0 mDataState=-1 dataActivity=0 mPhone.htcModemLinkOn:false hspa==true
07-02 17:11:02.542: D/PhoneStatusBarPolicy(1695): updateDataIcon(), silentresetvalue = 0, mTimerEnabled = false
07-02 17:11:02.542: D/PhoneStatusBarPolicy(1695): updateDataIcon(), in data service, do nothing
07-02 17:11:02.672: D/WifiStateMachine(1606): fetchRssiAndLinkSpeedNative RSSI = -66
07-02 17:11:05.685: D/WifiStateMachine(1606): fetchRssiAndLinkSpeedNative RSSI = -65
07-02 17:11:08.688: D/WifiStateMachine(1606): fetchRssiAndLinkSpeedNative RSSI = -64
07-02 17:11:09.449: I/global(2636): In close() at SocketHttpClientConnection
07-02 17:11:09.449: I/global(2636): call socket close in SocketHttpClientConnection, socket=Socket[address=www.google-analytics.com/74.125.236.101,port=80,localPort=43849]
07-02 17:11:11.701: D/WifiStateMachine(1606): fetchRssiAndLinkSpeedNative RSSI = -65
07-02 17:11:13.833: D/AutoSetting(2358): service - handleMessage() incoming message, what:50
07-02 17:11:13.833: D/AutoSetting(2358): service - handleMessage() stop self
07-02 17:11:13.843: D/AutoSetting(2358): service - onDestroy()
07-02 17:11:13.873: D/AutoSetting(2358): service - handleMessage() incoming message, what:100
07-02 17:11:13.893: D/AutoSetting(2358): service - onDestroy() END
07-02 17:11:13.903: D/Process(1606): killProcessQuiet, pid=2358
07-02 17:11:13.903: D/Process(1606): dalvik.system.VMStack.getThreadStackTrace(Native Method)
07-02 17:11:13.903: D/Process(1606): java.lang.Thread.getStackTrace(Thread.java:599)
07-02 17:11:13.903: D/Process(1606): android.os.Process.killProcessQuiet(Process.java:837)

2 个答案:

答案 0 :(得分:0)

在NearByHandler类中,由于具有空值而不是有效值,因此从标记中获取值的部分会引发异常。

所以使用 try / catch block 来处理从webServer获取数据并解析它的地方的异常。

答案 1 :(得分:0)

您将连接超时设置为30秒。可能是连接超时并且流已关闭。这在调试模式下很容易发生。您可以尝试增加这段时间。