我正在使用以下方法来获取我的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)
可能有什么问题?