I'm a absolute n00b, no shame here... I'm a long-time C#/.NET developer who's transitioning to Java as a primary technology and I'm having a serious issue getting *anything* to compile on *any* platform!
I get this error, "java.lang.NoClassDefFoundError" on my "Hello World" test SWT app in Eclipse. The thing is, I also get this same error when using eclipse on my Gentoo Linux machine or this here WinXP box...so I must be doing something that's typically lame and just don't know it.
Here's my SWT code (Eclipse on WinXP) giving me the error:
Here's the full error eclipse shows me:
I can do a simple command-line hello world and get the same error on Windows and Linux, like I said, so this must be an eclipse thing?
I've tried compiling a simple Hello World CLI app and I get the same error, so maybe it's not just an Eclipse issue?
Help! I'm pathetic!
posted 15 years ago
BTW - I *know* this has to do w/ the CLASSPATH env. variable but no matter *how* I set the stupid thing, it won't work.
I did this, just to test.
Setup the classpath variable to point to "c:\java_bin", a dir. I created myself.
I put MyClass.java which contains this code, in that dir.
...compiled it, then tried to run via command-line and I get this error STILL:
Exception in thread "main" java.lang.NoClassDefFoundError: MyClass/class
Can a moderator perhaps move this to another topic that would get the proper attention? I started here because I started w/ a SWT app that had this same problem but now I can't get *anything* to run.
To your second post: try declaring your class as public. Apart from that, you don't have to set the classpath if you do not use any extra classes and the class being run is in the current directory.
Now, with this SWT: I have never used it so I am just guessing. As it is not a core part of java you have to add it to class path. I don't use eclipse so I can't tell where you can do it.
Just a suggestion: If you have just started learning why don't you try Swing? I am not saying that it's better than SWT but it is a core part of java and apparently it is easier to cope with just 50 new things than 51 (50 + classpath) ;-)
Try this: Right click on your project and choose Java Build Path. Then click on Libraries tab and there you will find "Add External JARs" - click on it. Now you have to find swt.jar file which is located in <folder where you've installed eclipse>\plugins\org.eclipse.swt.win32_3.0.0\ws\win32 ( it's C:\Program Files\eclipse3.0final\\plugins\org.eclipse.swt.win32_3.0.0\ws\win32 in my case ). Now go Run>Run.. and click New. Now click on Arguments tab and in VM argument write:-Djava.library.path="<folder where you've installed eclipse>\eclipse3.0final\plugins\org.eclipse.swt.win32_3.0.0\os\win32\x86" ( it's -Djava.library.path="C:\Program Files\eclipse3.0final\plugins\org.eclipse.swt.win32_3.0.0\os\win32\x86" in my case ). Click Run and enjoy.
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop