Я анализирую данные JSON, которые начинаются примерно так ниже ...
[
{"title":"dummy", "content":"ajsfhk"},
{"title":"dummy", "content":"ajsfhk"},
{"title":"dummy", "content":"ajsfhk"},
]
А мой класс задач android asyn c находится ниже. Но это показывает, что "NegativeArraySizeException
"
class RetrieveFeedTask extends AsyncTask<Object, Void, String> {
@Override
protected String doInBackground(Object... arg0) {
int responseCode = -1;
try {
URL retailerUrl = new URL("https://clients.appatlantis.com/soldy/wp-json/wp/v2/soldy-clients?_embed");
HttpsURLConnection connection = (HttpsURLConnection) retailerUrl.openConnection();
connection.connect();
responseCode = connection.getResponseCode();
if (responseCode == HttpsURLConnection.HTTP_OK) {
InputStream inputStream = connection.getInputStream();
Reader reader = new InputStreamReader(inputStream);
int contentLength = connection.getContentLength();
char[] charArray = new char[contentLength];
reader.read(charArray);
String responseData = new String(charArray);
Log.e(TAG, "Parse Data "+responseData);
} else {
Log.e(TAG, "Parse Data Failed");
}
} catch (MalformedURLException e) {
Log.e(TAG, "URL Exeption: ", e);
} catch (IOException e) {
Log.e(TAG, "IO URL Exeption: ", e);
} catch (Exception e) {
Log.e(TAG, "Exeption Caught: ", e);
}
return "Response Code "+responseCode;
}
}
А вот трассировка исключения
2020-04-10 15:12:31.322 27385-27449/com.appatlantis.soldy E/MainActivity: Exeption Caught:
java.lang.NegativeArraySizeException: -1
at com.appatlantis.soldy.MainActivity$RetrieveFeedTask.doInBackground(MainActivity.java:149)
at com.appatlantis.soldy.MainActivity$RetrieveFeedTask.doInBackground(MainActivity.java:132)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Я не очень разбираюсь в JSON.