I'm working on some other guys code and he tries to read data from a JSON config file. It always worked, but I'm suddenly getting a NoSuchMethodError.
This is the part that's causing the problem:
config_bcs_filterstatuscodes = new LinkedList<>();
for (Object filtercode : appconfig.getJSONObject("projektron_bcs").getJSONArray("filter_statuscodes").toList()) {
config_bcs_filterstatuscodes.addLast(filtercode.toString());
}
The code tries to convert a List of Objects to a List of Strings.
The error I'm getting:
Exception in thread "main" java.lang.NoSuchMethodError: org.json.JSONArray.toList()Ljava/util/List;
at middleware.Main.main(Main.java:103)
I have no idea why it suddenly tells me that there is no such method, because it always worked until now.
CodePudding user response:
The JSONArray from "org.json" doesn't have a toList() method You should iterate directly the JSONArray object like this:
for (int i=0;i<jsonArray.length();i ){
config_bcs_filterstatuscodes.add(jsonArray.getString(i));
}