java.lang.NoSuchMethodError: org.json.JSONArray.isEmpty()Z
I tried using the isEmpty()
method of JSONArray
from the org.json
JAR.
I'm using IntelliJ as my IDE. I'm not using anything close to reflection in my code. I declare a JSONArray
, and after some lines trying to check if it is empty or not, however I get this Error when trying to use isEmpty()
.
I did work around the issue simply by using jsonArray.length() > 0
, but the error message is what fascinates me. I looked into the de-compiled .class file of JSONArray, and the method isEmpty()
exists, and has a public access modifier. Futhermore, InteliiJ is suggesting me I can use isEmpty()
when typing the code. So what could be causing this error to occur?
JSONArray filesJsonArray = new JSONArray();
JSONObject fileObject = new JSONObject();
fileObject.put("fileId",fileId);
fileObject.put("fileName",fileName);
fileObject.put("mimeType",mimeType);
filesJsonArray.put(fileObject);
if (!filesJsonArray.isEmpty()){ //the condition check here throws the error.
}
(Catch blocks were dismissed for brevity)
In the class I'm using this code, this is all my imports
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.nio.ByteBuffer;
import java.sql.*;
import java.util.Base64;
If you are using spring boot, then you can try this:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<exclusions>
<exclusion>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
</exclusion>
</exclusions>
</dependency>
It worked for me..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With