Android XML解析器流的意外结束

时间:2018-10-27 15:21:13

标签: java xml-parsing

所以这发生了:

W/System.err: java.net.ProtocolException: unexpected end of stream
W/System.err:     at com.android.okhttp.internal.http.Http1xStream$FixedLengthSource.read(Http1xStream.java:396)
W/System.err:     at com.android.okhttp.okio.RealBufferedSource.read(RealBufferedSource.java:50)
        at com.android.okhttp.okio.RealBufferedSource.request(RealBufferedSource.java:71)
        at com.android.okhttp.okio.RealBufferedSource.require(RealBufferedSource.java:64)
W/System.err:     at com.android.okhttp.okio.RealBufferedSource.readIntLe(RealBufferedSource.java:237)
        at com.android.okhttp.okio.GzipSource.consumeTrailer(GzipSource.java:174)
        at com.android.okhttp.okio.GzipSource.read(GzipSource.java:92)
W/System.err:     at com.android.okhttp.okio.RealBufferedSource$1.read(RealBufferedSource.java:371)
        at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:288)
        at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:351)
        at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:180)
        at java.io.InputStreamReader.read(InputStreamReader.java:184)
        at java.io.BufferedReader.fill(BufferedReader.java:172)
        at java.io.BufferedReader.readLine(BufferedReader.java:335)
        at java.io.BufferedReader.readLine(BufferedReader.java:400)
        at com.vremego.vremego.NetworkUtils.getWeatherInfo(NetworkUtils.java:56)
W/System.err:     at com.vremego.vremego.WeatherLoader.loadInBackground(WeatherLoader.java:30)
        at com.vremego.vremego.WeatherLoader.loadInBackground(WeatherLoader.java:11)
W/System.err:     at android.support.v4.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:307)
        at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:60)
        at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:48)
        at android.support.v4.content.ModernAsyncTask$2.call(ModernAsyncTask.java:141)
W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/System.err:     at java.lang.Thread.run(Thread.java:764)
W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@20c306f
D/EGL_emulation: eglMakeCurrent: 0xe62208a0: ver 2 0 (tinfo 0xe9a072c0)

我正在从Web上解析XML,以显示在android活动上显示的天气,它适用于较小的尺寸(最多3个对象),但是当我对4,5执行相同操作时,它只会抛出该异常(全部在实际解析之前):

   URL requestURL = new URL(queryString);

    urlConnection = (HttpURLConnection) requestURL.openConnection();
    urlConnection.setRequestMethod("GET");
    urlConnection.connect();

    InputStream inputStream = urlConnection.getInputStream();

    StringBuilder builder = new StringBuilder();

    reader = new BufferedReader(new InputStreamReader(inputStream));

    String line;
    while ((line = reader.readLine()) != null)
        builder.append(line);

   if (builder.length() == 0)
       return null;

    weatherResultString = builder.toString();

    if(format_podatkov.equals("xml")) {
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
        Document dokumentXML = docBuilder.parse(new InputSource(new StringReader(weatherResultString)));

在while循环条件中引发异常...有什么想法吗?

0 个答案:

没有答案