Reputation: 1817
As i have some issues while working with Android's JSON (i.e. org.json), so here i'm using json simple. But when i try to convert string into json object using json parser, such as,
JSONObject masterJson = (JSONObject) new JSONParser().parse(stringdata);
an error occur :
java.lang.NoClassDefFoundError: org.json.simple.JSONObject
Please suggest a method. Thanks in advance.
Upvotes: 2
Views: 1816
Reputation: 1817
From my experience, even if we add the respective jar file, it wont work properly. For adding an external jar file, i followed the steps below:
Right click on project in eclipse -> Buildpath -> Configure Build path -> Java Build Path (left Pane) -> Libraries(Tab) -> Add External Jars -> Select your jar and select ok.
But it didn't work. After googling a lot, i found that, after adding the jar file, select the "Order and Export" tab, then check the currently added external file, finally refresh the project. Then it will work perfectly.
Refer this question: How can I resolve this java.lang.NoClassDefFoundError: org.json.simple.JSONObject error? In this question, we cant find an answere, but the correct answere was added as a comment. Thanks to @peeskillet for adding the comment.
Upvotes: 1
Reputation: 414
If there's problem with import .jar try something else.
Do you use gradle? If yes import in dependencies
this line: compile 'com.googlecode.json-simple:json-simple:1.1'
Upvotes: 0
Reputation:
Looks like you have missed including the filename.jar
in your classpath. Include the same and it should get solved.
Hope this helps !
Upvotes: 0