• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java lang NoClassDefFoundError with SWT Class

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm very new to Java and learning by typing some example code. I've wrote a small class that uses a SWT GUI but I'm getting the following error when I try to run it in the command line (in Eclipse, no probs!) ....

Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Decorations

I've tried Java -cp . SWTTest
I also got the path to Java set up correctly (D:\Java\jre1.5.0_06\bin\)
What could be the problem abou this?

Another thing that puzzles me is that another small command line Java class that I'm using now only can be started with ...

java -cp . cmdUtil

but a while back I could start it without the -cp .
(In both cases it was not in a default Java class folder).

Would be cool to figure this out! I've been using the search function and found many topics about this but none of them helped me solving it!
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the above error is due to the particular jar or lib file is missing ..
open notepad ,copy the content of the program ..save it and run as ordinary java program from command prompt..people like opu should start write coding using notepad..then only u will know about the classes and methods available in java

Thanks
Ramesh.N
 
Sascha Balkau
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I'm not sure what you mean? I should start using Notepad? How does it help me? I'm using Eclipse alot for wrinting ActionScript so I'm not completely unfamiliar with it.

The error looks like some SWT specific stuff is missing but what do I have to do to get this working?

Thanks for any help on this!
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NoClassDefFoundError means that the Java runtime environment can't find a class that your program needs. In 99.9% of the cases, this means your classpath is incorrect.

You are starting your application with: java -cp . SWTTest
So you are only including the current directory (".") in the classpath.

Add the necessary JAR file or directory that contains the SWT classes to your classpath.
 
Sascha Balkau
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jesper Young:
NoClassDefFoundError means that the Java runtime environment can't find a class that your program needs. In 99.9% of the cases, this means your classpath is incorrect.

You are starting your application with: java -cp . SWTTest
So you are only including the current directory (".") in the classpath.

Add the necessary JAR file or directory that contains the SWT classes to your classpath.



Ok, I get what you mean! Now I'm trying it with the following ...

>java -cp "D:\Eclipse\plugins\org.eclipse.swt.win32.win32.x86_3.1.2.jar" SWTDemo

I've also added a . to the CLASSPATH env variable so I don't need the -cp .
but it still doesn't work and gives me an error, this time only a java.lang.NoClassDefFoundError. Obviously it's the correct jar file for the SWT classes but something is still wrong.
[ April 21, 2006: Message edited by: Sascha Balkau ]
 
Sascha Balkau
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've figured it out finally!
For the afterworld:

Download the standalone SWT library and DLL's ...
http://www.eclipse.org/swt/

unpack swt.jar to your JRE/lib folder, copy the three swt...dll to your JRE/bin folder (ideally).
On the environment variable CLASSPATH add .;path/to/JRE/lib
On the environment variable PATH add path/to/JRE/bin (if not already there)

now SWT Java apps should be able to run on the command line by simply using
Java YourApp.

... always refreshing that nowhere guides can be found that explain this! :/
 
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much @Sascha. You really helped me out!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic