java


How can I solve “org.json.simple.JSONObject cannot be resolved”?


When I try to open my jsp through Tomcat, I receive the following messages:
The type org.json.simple.JSONObject cannot be resolved. It is indirectly referenced from required .class files.
The method getJSONObject() from the type Ejercicio refers to the missing type JSONObject.
I have a java class that goes like this:
package E;
import org.json.simple.*;
import javax.json.*;
import org.json.*;
public class Ejercicio {
public int a;
public String b;
public Ejercicio (int a, String b) {
this.a=a;
this.b=b;
}
public JSONObject getJSONObject() {
JSONObject obj = new JSONObject();
obj.put("a", a);
obj.put("b", b);
return obj;
}
}
My jsp goes as follows:
<%#page import="java.io.*" %>
<%#page import="java.util.*"%>
<%#page import="E.Ejercicio"%>
<%#page import="javax.json.*"%>
<%#page import="org.json.simple.*"%>
<%#page import="org.json.*"%>
<%#page import="net.sf.json.*" %>
<%
ArrayList<Ejercicio> miArray = new ArrayList<Ejercicio>();
miArray.add(new Ejercicio (1,"Hola"));
miArray.add(new Ejercicio (2,"Caracola"));
miArray.add(new Ejercicio (3,"Perola"));
for (Ejercicio temp:miArray) {
out.println("<p>"+temp.b+"</p>");
}
JSONArray jsonArray = new JSONArray();
for (int i=0; i < miArray.size(); i++) {
jsonArray.put(miArray.get(i).getJSONObject());
}
%>
I have added a lot of jars to both the lib folder inside WEB-INF and the Tomcat lib trying to solve the problem with no results (commons-beanutils-1.8.1, commons-collections-3.2.1, commons-lang-2.5, commons-logging-1.1.1, ezmorph-1.0.6, java-json, javax.json-1.0, json-lib-2.4-jdk15, json-rpc-1.0, json-simple-1.1.1-sources, org.json).
When I compiled the java class I got the "Some input files use unchecked or unsafe operations" message. Could this be related to the jps not compiling?
Firstly, you don't need the json-simple.jar in your project.
Therefore remove the import org.json.simple.*
Secondly, the best practice is to import only the required classes from your jar.Therefore you can replace import org.json.*; by
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONString;
You are missing json-simple-1.1.1.jar from your classpath.
if you are using Maven, add below into your pom.xml.
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
Or you can download it from here.
Is some version of json-simple.jar in your project libs ?

Related Links

Double dot notation no longer works out of classpth (out of bin when using eclipse) for Class.getResouce()?
Converting media content into string in Java
i want to putHeader to my url when timeout equal 5s but it error “java.lang.IllegalStateException: Response has already been written”
String replaceAll not working with string object [duplicate]
c3p0 access denied for user 'root'#'localhost' (using password yes)
Custom Maven plugins and libraries
AJAX response is different from java/hibernate returned string
How to use unidirectional one-to-many mapping relationship?
Running a Java Application on a server from my PC
CSV Java file reading and saving (in different ArrayList)
button initialization in other function instead of OnCreate() method
How Do I create a Json Array in a Json Array?
How to get/modify player x,y & z coordinates minecraft?
Upgrading java version to use latest from JDK 8
Count sibling classes of ontology (from .owl) file using Java
Change Windows 10 Wallpaper in Java

Categories

HOME
cakephp
pandas
cloud
testng
listview
amazon-ec2
view
webstorm
cvs
analysis
cmd
contact
rascal
postgres-xl
dtrace
circuit
iron-router
clojurescript
foselasticabundle
transformation
interop
intentfilter
dcevm
hammerspoon
sqlcipher
pepper
user-interaction
elasticsearch-net
vision
bluestacks
stormpath
data-manipulation
airconsole
gtrendsr
copying
calibre
form-data
rotational-matrices
cloud-code
amazon-kinesis-kpl
ios5
azure-ml
greenrobot-eventbus
sql-server-agent
spring-security-kerberos
import-from-excel
gpx
scorm
wso2carbon
jsch
flickr-api
fault
rainbowtable
atomicity
togetherjs
yii2-extension
tropo
svmlight
colorama
directory-structure
hittest
google-cdn
probability-density
storekit
jwplayer7
python-stackless
rvest
oauth2client
pyke
uid
unity-networking
srand
qtableview
wyam
apache-commons-fileupload
e10s
lustre
system.reflection
fscommand
tween
jscript.net
xcode-6.2
java-metro-framework
bitcoinj
xojo
hippomocks
industrial
jplaton
gridcontrol
sqlperformance
kyotocabinet
free-variable
tinn-r
anonymous-methods
rdoc
multipage
wse3.0
blackberry-playbook
recent-documents
file-comparison
sortable-tables
mirah
bespin
firefox4
project-hosting
aquaticprime
w3wp
rtml

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile