• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

NoClassDefFoundError

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi to every one I had the java 1.6 version in my mechine


C:\>java -version
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

I written the following simple program.

class Test
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}

I saved this in the C:\ directory. I am able to compile this successfully but when I want try to run this I am getting the following exception.

Exception in thread "main" java.lang.NoClassDefFoundError: Test



C:\>javac Test.java

C:\>java Test
Exception in thread "main" java.lang.NoClassDefFoundError: Test

why I am getting this Exception at run time please send me the reply if any one had idea.

Thanks in advance.
Ishmayel.

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well it is possible that your classpath variable don't have a . in it
 
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
What does your CLASSPATH look like? It most likely does not contain '.' (the current directory), as Ivan suggests. Note that if you do not set the CLASSPATH evironment variable at all, Java will automatically look in the current directory.

Since this question does not really have much to do with the SCJP exam, I am moving this to the Java in General (Beginner) forum. Please continue there.

For more information about CLASSPATH, see: http://faq.javaranch.com/java/HowToSetTheClasspath
[ April 28, 2008: Message edited by: Jesper Young ]
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this

c:\cd "JAVAPRJ"
c:\directory>javac hello.java
c:\directory>java hello

assume that java file stored in a directory named "JAVAPRJ"
 
ishmayel vemuru
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I already set the classpath,path and JAVA_HOME but why the simple java program is not running on my mechine. I try to run the simple *.class file
with package and without package but I did not.

Any *.java file is compiling fine but not running.

what is the problem..?

Actually I have Java 1.5 version on my mechine I set every thing in environment variables but that was run some day's with out any problem.
After some time I installed Net Beans IDE 6.0 with that java 1.6 is installed on my mechine...I didn't set any environment variable for java 1.6 but when I try the follwoing command I am getting this ::

C:\>java -version
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)


If any one had idea help me.
Thanks & regards...
Ishmayel.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this command
C:\>java -cp . Test

Note the spaces around the .
 
ishmayel vemuru
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi..
Thanks for your repply..

I tried that command java -cp . Test
Now my .class file is running on my mechine...
But what is the difference between the following commands.

c:\>java Test
&&

C:\> java -cp . Test

Thanks & Regards,
Ishmayel.
 
Marshal
Posts: 80269
430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The difference is that the -cp . adds the "." to the classpath, which means that "java" looks for whichever class you are executing in the "." as well as the rest of the classpath.

The "." means the directory your command prompt happens to be open in, the current directory.
 
ishmayel vemuru
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi..
why I have to alway run my .class file with java -cp . Test
how can I eliminate this ?
i already set my CLASS PATH, PATH and JAVA_HOME.
can any one have any idea..?
Thanks in advance...
Ishmayel.
 
Campbell Ritchie
Marshal
Posts: 80269
430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Plase copy and paste your CLASSPATH environment variable.
And why you are working at the root of your C drive rather than in a "Java" folder? Please use mkdir to create a "java" folder and try working inside that.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ishmayel vemuru:
Hi..
why I have to alway run my .class file with java -cp . Test
how can I eliminate this ?
i already set my CLASS PATH, PATH and JAVA_HOME.
can any one have any idea..?
Thanks in advance...
Ishmayel.



When you're just learning and only writing small apps, it is not a problem to use the CLASSPATH environment variable. However, once your apps start getting more complicated and you need to make use of different 3rd party jar files with each app then the CLASSPATH variable will become very difficult to maintain. Using the -cp option will enable you to specify a different classpath for each of your applications. If you don't want to write the whole command line each time, then you can just put it in a btach/script file and run that. Later on you will learn about jar files which will also make it easier.
 
And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic