Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can't compile ANYWHERE...

 
Vinnie Jenks
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

Thanks!
 
Vinnie Jenks
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


What gives?

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.

Thanks!
 
Petr Blahos
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vinnie,

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) ;-)

Best regards, Petr
 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinnie, have you tried putting a . in the classpath, this will tell Java to look in the current directory for the class.

e.g. something like "C:\stuff\;.;"
 
Vinnie Jenks
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I actually started another thread in the beginners forum, see here for where I'm at currently, still having absolutely no luck even running the simplest of java apps.

http://www.coderanch.com/t/397231/java/java/cannot-run-simple-Java-app
 
Boris Benda
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic