• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

java.lang.NoClassDefFoundError problem

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guy,
I am using JCreator to compile and code java, but when I clicked "run project", it showed that
--------------------Configuration: <Default>--------------------
java.lang.NoClassDefFoundError: HelloPrinter
Caused by: java.lang.ClassNotFoundException: HelloPrinter
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)
Could not find the main class: HelloPrinter. Program will exit.
Exception in thread "main"
Process completed.

I google it before and I changed my environment variables to
CLASSPATH .;
JAVA_HOME C:\Program Files\Java\jdk1.6.0_23
PATH .;%SystemRoot%\system32;%JAVA_HOME%\bin;
but it still not working.
Can anyone please help to solve this??
Thanks.
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use the CLASSPATH environment variable. It will only cause more problems then it will solve. Just use the -cp argument of java.

The error that you're getting means that the class that you're trying to use can't be found. Is it on the classpath?
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the javaranch.
 
ray wongray
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Wouter Oet wrote:Don't use the CLASSPATH environment variable. It will only cause more problems then it will solve. Just use the -cp argument of java.

The error that you're getting means that the class that you're trying to use can't be found. Is it on the classpath?



thanks. I deleted the CLASSPATH variable but it still not working. what should I do??
 
Marshal
Posts: 70234
282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Confirm that the files you want are in the directory you think they are in. Tell us what you found.
Get your command prompt to show you what classpath it is using. Not quite sure what the instruction for that is, however. Something like ECHO %CLASSPATH%, or %CLASSPATH%, but I can't remember the details.
 
Greenhorn
Posts: 21
Mac Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can just type set and hit enter in Command Prompt (in Windows) and it will display all the environment variables used. PATH, CLASSPATH and etc.
 
ray wongray
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Confirm that the files you want are in the directory you think they are in. Tell us what you found.
Get your command prompt to show you what classpath it is using. Not quite sure what the instruction for that is, however. Something like ECHO %CLASSPATH%, or %CLASSPATH%, but I can't remember the details.



I saved the java code to C:\bin
and the result of ECHO %CLASSPATH% is
.;C:\bin;C:\Program Files\Java\jdk1.6.0_23\lib\dt.jar;C:\Program Files\Java\jdk1.6.0_23\lib\tools.jar
 
Markas Korotkovas
Greenhorn
Posts: 21
Mac Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
did you remember to compile all your Java classes? Use javac?
 
ray wongray
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Markas Korotkovas wrote:did you remember to compile all your Java classes? Use javac?



Could you please tell me how to do it??? I use JCreator and I thought it already compiled all the java class when I clicked "run project"
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will probably do that for you but you need to be able to walk before you run. What I mean by that you need to be able to do it manually before you resort to an IDE to do it for you. That way you'll understand what is happening and solving problems on a lower level is usually easier.

Assuming that you use Windows: go through this tutorial otherwise pick your OS here.
 
Campbell Ritchie
Marshal
Posts: 70234
282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't like the use of your bin file. Nor the classpath you have set. You might be better off without that classpath at all.
When you open the command line write this

mkdir javawork
cd javawork

Next time you only need the second line. Obviously you can choose any sensible name for your Java™ folder. If you delete your classpath, the compiler will impute a class path of "." = current directory, which is what you want at this stage.
 
    Bookmark Topic Watch Topic
  • New Topic