-1

I downloaded a JTree program from http://kodejava.org/examples/566.html site. It is compiling but when running the program, it is giving this exception:

Exception in thread "main" java.lang.NoClassDefFoundError: JTreeDifferentNodeIcon (wrong name: org/kodejava/example/swing/JTreeDifferentNodeIcon)
    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)

Can any one tell me what will be the problem?? ThankU.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
user27510
  • 37
  • 3
  • 2
    for better help sooner post an [SSCCE](http://sscce.org/), short, runnable, compilable, – mKorbel Feb 26 '13 at 08:03
  • 1
    A [NoClassDefFoundError](http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/NoClassDefFoundError.html) is thrown when a class definition is missing from a project. So it existed when the program was last compiled, but it has since disapeared. As @mKorbel stated, posting an SSCCE would be the best thing to do now. – christopher Feb 26 '13 at 08:13
  • 1
    As said by @mKorbel a SSCCE is needed for better support but just as first check, did you have created your class in the package `org/kodejava/example/swing/JTreeDifferentNodeIcon`? Because this seems to be the problems since the code posted should be working properly. – araknoid Feb 26 '13 at 08:19

2 Answers2

1

Your package is org.kodejava.example.swing. You can try building javac by specifying the -d option. For better understanding let's assume that you have the source file in your desktop say "C:\Users\sarath_sivan\Desktop\JTreeDifferentNodeIcon.java"

  • First, you may please open the command prompt and change directory to C:\Users\sarath_sivan\Desktop (cd C:\Users\sarath_sivan\Desktop).
  • Then create a new folder named classes there (mkdir classes).
  • Now, you can build with javac, specify the "-d" option to tell it the base directory, and it will create the appropriate package structure. (javac -d classes JTreeDifferentNodeIcon.java)
  • You could then run java -cp classes org.kodejava.example.swing.JTreeDifferentNodeIcon which will produce the output something like this:

enter image description here

Hope this helps! Thank you...

1218985
  • 7,531
  • 2
  • 25
  • 31
0

It says "NoClassDefFoundError" (no class definition found error) so I think you're using a class which is not defined before (probably because mistyping or forgetting to import something or deleting a file or moving the final file from one folder to another)
P.S. I haven't looked at the code yet (don't have enough time)