A
A
artshelom2018-04-05 22:11:54
Java
artshelom, 2018-04-05 22:11:54

How to fix error: "IllegalStateException: closed" when creating JSONObject?

Loading a page online and trying to make it a JSON object. An error occurs:

E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
                  Process: ru.toster.ru.toster.uggu, PID: 2320
                  java.lang.IllegalStateException: closed

The code:
@RequiresApi(api = Build.VERSION_CODES.O)
            @Override
            public void onResponse(Call call, Response response) throws IOException {
                SQlite sQlite = new SQlite(context);
                JSONParser parser = new JSONParser();
                String[] groups = null;


                try {
                    JSONArray object = (JSONArray) parser.parse(response.body().string());
                } catch (ParseException e) {
                    e.printStackTrace();
                }

                if (!sQlite.getGroup().equals(""))
                    activity.saveRasp(response.body().string().split(sQlite.getGroup()+"\":")[1].split(Pattern.quote("},"))[0]+"}", groups);//.split("]]},\"")[0]+"]]}"
                call.cancel();
            }

(The json library is org.json.simple)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2018-04-06
@artshelom

https://square.github.io/okhttp/3.x/okhttp/okhttp3...
We read until enlightenment.
The response body can be consumed only once.
And you do it twice.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question