Parse JSON string in Java - java

I'm trying to parse a JSON string in Java but I cant figure out how!
I'm using lib-JSON right now:
import net.sf.json.*;
.
String jsonStr = "{'string':'JSON', 'integer': 1, 'double': 2.0, 'boolean': true}";
JSONObject jsonObj = (JSONObject) JSONSerializer.toJSON(jsonStr); // this line crashes
I get no compilation errors but when i run the program it says:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at ircbot.plugins.SiteTitle.<init>(SiteTitle.java:28)
at ircbot.Main.main(Main.java:10)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 14 more
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
It sounds like I'm missing some dependencies, but I don't know how to find out if or which!
Thanks in advance!

It seems you have not imported need jar file for class "org.apache.commons.lang.exception.NestableRuntimeException"
There are many classes that we use in our Java program and which don't come with Java. So we need to put Suitable Jar file for them.

I recomend grepcode
Just enter the class name and you get a list of the known versions of jars
Example: here

You are missing jar file. No jar file in your class path.
see this Reading JSON file error

org/apache/commons/lang -> http://commons.apache.org/lang/
Basically, use Google and get the respective jar.

Your JSON String also not valid, This the valid JSON,
{"string": "JSON","integer": "1","double": "2.0","boolean": "true" }

These are the dependencies -
jakarta commons-lang 2.5
jakarta commons-beanutils 1.8.0
jakarta commons-collections 3.2.1
jakarta commons-logging 1.1.1
ezmorph 1.0.6
are you sure you added all of them in your classpath.

Related

Java: Including jar in classpath

I created a Java project in Eclipse and created a simple class with a main method.
Problem: when I run the program(without any server etc), I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
at autoPEC.main(autoPEC.java:6)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.DecoderException
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 1 more
What I tried to solve the problem: included path to commons-codec.jar in the environment variables JAVA_HOME by putting a semicolon after the jdk path
Result: class still does not run
I think that the problem could be that I am not correctly including the classpath. How should I do this?
Google the missing jar and include it in the Java Build path
Reason for this exception is missing of a jar.
please add the jar(Commons-codec.jar) file needed for this org.apache.commons.codec.DecoderException
Download it from here
http://commons.apache.org/proper/commons-codec/download_codec.cgi
then put it in your classpath

How to convert jar file to DMG from windows Operating System

I had Developed Java Application in Windows 7.
And I had made JAR file of that application.
Now I want to convert that File into DMG format which is compatible for MAC Operating System.
Can any one Suggest me steps please?
I tried into terminal But got this errors.
DEVs-MacBook-Proist idev$ java -jar Soul_Spotter.jar
Exception in thread "main" java.lang.UnsupportedClassVersionError: idev/soulspotter/Login : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
The below link explains the steps. I've also copied the answer which worked for me.
Copied from convert java app to mac installer...dmg
Use "Jar Bundler" in the XCode download from Apple Developer
Connection.
http://developer.apple.com/technology/xcode.html
You will need to register for a free account.
Steps: http://www.centerkey.com/mac/java/

Google Developer Tools Java FATAL ERROR

Thanks in advance for your help.
I am new to the Google developer tools and I have been messing around trying to figure out how to get one of their features to work.
This one most specifically:
https://developers.google.com/appengine/docs/java/tools/eclipse#Running_the_Project
So this is how far I've gotten.
I updated my Java package to 1.7. I installed the Google plug in for eclipse.,
I created a new project named "Guestbook", made sure the boxes were checked, run->DebugAs-> WebApplication, and then I get this huge error:
Exception in thread "main" FATAL ERROR in native method: processing of
-javaagent failed java.lang.UnsupportedClassVersionError: com/google/appengine/tools/development/agent/AppEngineDevAgent :
Unsupported major.minor version 51.0 at
java.lang.ClassLoader.defineClass1(Native Method) at
java.lang.ClassLoader.defineClassCond(ClassLoader.java:637) at
java.lang.ClassLoader.defineClass(ClassLoader.java:621) at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) at
java.net.URLClassLoader.access$000(URLClassLoader.java:58) at
java.net.URLClassLoader$1.run(URLClassLoader.java:197) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:190) at
java.lang.ClassLoader.loadClass(ClassLoader.java:306) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at
java.lang.ClassLoader.loadClass(ClassLoader.java:247) at
sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:280)
at
sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:338)
I don't know what all this means.
I am still fairly new to java, so any help would be excellent.
Hope all is well

Java NoClassDefFoundError in Command Line

I'm getting the NoClassDefError when I try to run my program from the command line. It works fine in Netbeans, and javac compiles correctly.
I have a class called DistributedSystem which so far is only supposed to print "hello.".
The directory is src/distributedsystem/ which contains DistributedSystem.java, and DistributedSystem.class after the compile.
If I'm inside src/distributedsystem/ and run
java DistributedSystem
then I get
Exception in thread "main" java.lang.NoClassDefFoundError: DistributedSystem (wrong name: distributedsystem/DistributedSystem)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
I also get the exact same error if I'm inside src/distributedsystem/ and run
java -cp . DistributedSystem
which is what I thought would fix the problem. I have also tried making sure classpath isn't set somewhere else, even though -cp should overwrite it. Anyone have any ideas what could be wrong?
Go to folder src then compile from there and then run
The classpath should point to the base directory. It looks as if you are attempting to run class DistributedSystem in package distributedsystem, but your classpath is set to project/bin/distributedsystem instead of project/bin.

Rubymine startup error java.lang.NoClassDefFoundError: com/intellij/util/lang/UrlClassLoader

I am using Ubuntu 11.04, when i start RubyMine3.1 it gave this error.
Exception in thread "main" java.lang.NoClassDefFoundError: com/intellij/util/lang/UrlClassLoader
at com.intellij.idea.Main.main(Main.java:55)
Caused by: java.lang.ClassNotFoundException: com.intellij.util.lang.UrlClassLoader
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 1 more
I tried every thing, i also have sun-java installed, set it default by update-java-alternatives, also my JAVA_HOME, JDK_HOME, RUBYMINE_JDK points to the sun-java directory, but still no success.
Does any one have any idea about it?
Damaged download or some classes left from older version? Try to download again and unpack into an empty directory.
Did you install any third-party plug-ins? In this case you should try to delete them from the plugins directory.
The class which fails to load is located in RubyMine/lib/util.jar. Maybe you are using an old version of rubymine.sh which doesn't add util.jar to the classpath?

Categories