0

我正在制作一个应用程序,我可以在其中调用 web 服务并填写数据。但是由于发生了一些奇怪的事情。我遇到了带有 IOException 的 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)

代码 ::

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)
4

2 回答 2

0

在 NearByHandler 类中,您从标签中获取值的部分正在引发异常,原因是具有空值而不是有效值。

因此,请使用try/catch 块在您从 webServer 获取数据并解析它的地方处理异常。

于 2012-07-02T16:03:20.427 回答
0

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

于 2012-07-02T16:09:26.947 回答