Reputation: 4438
I have to convert an Xml file at a very heavy http into a Json file.
I tried to use: implementation 'org.json: json: 20180813'
But it gives me the following error:
Caused by: java.lang.NoSuchMethodError: No direct method <init> (Ljava / me / Reader;) V in class Lorg / json / JSONTokener; or its super classes (declaration of 'org.json.JSONTokener' appears in /system/framework/core-libart.jar)
at org.json.XMLTokener. <init> (XMLTokener.java:57)
at org.json.XML.toJSONObject (XML.java:516)
at org.json.XML.toJSONObject (XML.java:548)
at org.json.XML.toJSONObject (XML.java:472)
If I go to the build.gradle file, on the lib in question it tells me:
json defines classes that conflict with classes now provided by Android. Solutions includes finding newer versions or alternative libraries that do not have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar.
So I tried to use: Link
But it does not work.
Can you tell me where I'm wrong? Or a solution.
Code http:
private class Html extends AsyncTask<Void, Void, Void> {
private String url = "https://pastebin.com/raw/ExP2Mm2k";
private JSONArray listCh = new JSONArray();
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
try {
Log.v("Class:" + TAG, "doInBackground:" + url);
String jsonString = Jsoup.connect(url).execute().body();
//Log.v("Class:" + TAG, "" + jsonString);
/* try {
JSONObject xmlJSONObj = XML.toJSONObject(jsonString);
String jsonPrettyPrintString = xmlJSONObj.toString(4);
System.out.println(jsonPrettyPrintString);
} catch (JSONException je) {
System.out.println(je.toString());
}*/
try {
JSONObject json = new JSONObject(jsonString);
JSONArray list = json.getJSONObject("list").getJSONArray("item");
//Log.v("Class:" + TAG, String.valueOf(listCh));
} catch (JSONException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
populateListItem(listCh);
}
}
Upvotes: 2
Views: 2004
Reputation: 36353
I had to bring in org.json lib as source files to change the package name to get it to stop conflicting with the org.json packaged with Android.
If you don't want to hand edit the package names, you might be able to use something like jarjar
Upvotes: 1