简体   繁体   中英

IOException raise in parser

i am make an application in which i get call webservices and fill data. but here due to some odd things are occure.i got error with arrayIndexoutofBound with IOException... i have use SAX parser for parseing simple webservices.

Error::

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
            }

Update:

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)

In NearByHandler class, the section where you fetching the values from the tag, is throwing an exception, due to the reason of having null values instead of valid values..

So use try/catch block to handle the exception at the place where you are fetching the data from the webServer and parsing it..

You are setting connection timeout to 30 seconds. May be connection is timing out and stream is closed. This could easily happen in debug mode. You may try to increase this period.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM