0

我正在使用以下方法来获取我的 json 数据:

private JsonReader getJsonData(String link) {
    HttpURLConnection urlConnection = null;

    try {
        URL url = new URL(link);
        urlConnection = (HttpURLConnection) url.openConnection();

        InputStream is = new BufferedInputStream(urlConnection.getInputStream());

        //Log.e("Output", printOutput(is));
        reader = new JsonReader(new InputStreamReader(is, "UTF-8"));

    } catch (NullPointerException | IOException e) {
        e.printStackTrace();

        Snackbar.make(layout, Constants.SERVER_ERROR, Snackbar.LENGTH_SHORT).show();
    } finally {
        if (urlConnection != null) {
            urlConnection.disconnect();
        }
    }

    return reader;
}

它工作正常并且解析正确。但现在我在日志上收到以下错误。

09-17 14:53:39.082  24761-28286/com.radioafrica.music W/System.err﹕ java.io.IOException: closed
09-17 14:53:39.088  24761-28286/com.radioafrica.music W/System.err﹕ at com.android.okio.RealBufferedSource$1.read(RealBufferedSource.java:164)
09-17 14:53:39.088  24761-28286/com.radioafrica.music W/System.err﹕ at java.io.BufferedInputStream.read(BufferedInputStream.java:290)
09-17 14:53:39.088  24761-28286/com.radioafrica.music W/System.err﹕ at java.io.InputStreamReader.read(InputStreamReader.java:231)
09-17 14:53:39.088  24761-28286/com.radioafrica.music W/System.err﹕ at com.google.gson.stream.JsonReader.fillBuffer(JsonReader.java:1263)
09-17 14:53:39.088  24761-28286/com.radioafrica.music W/System.err﹕ at com.google.gson.stream.JsonReader.nextNonWhitespace(JsonReader.java:1309)
09-17 14:53:39.088  24761-28286/com.radioafrica.music W/System.err﹕ at com.google.gson.stream.JsonReader.consumeNonExecutePrefix(JsonReader.java:1514)
09-17 14:53:39.088  24761-28286/com.radioafrica.music W/System.err﹕ at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:523)
09-17 14:53:39.088  24761-28286/com.radioafrica.music W/System.err﹕ at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:368)

可能是什么问题?

4

0 回答 0