Solved

main exception

Posted on 2002-04-10
4
170 Views
Last Modified: 2010-03-31
hi experts, l'm having a terrible problem. i just downloaded the j2sdk1.4.0 and get it installed in windows me. i had set the path=c:\j2sdk14\bin where i installed the jdk and wrote a simple program to test as follow

public class test
{
        public static void main( String args[] )
        {
                System.out.println("testing");

        }

}

saved as test.java. i ran "javac test.java" and returned no error.then i ran "java test" and return "exception in thread "main" java.lang.NoClassDefFoundError :test". i really do not know what happens. pls help.
0
Comment
Question by:Explorer060599
  • 3
4 Comments
 
LVL 92

Expert Comment

by:objects
Comment Utility
It happens because your class is not in your classpath.
You need to include the directory that contains your class in you classpath.

eg. if your class file is in c:\javastuff\test.class

then use:

java -classpath c:\javastuff test

or if you are in the same directory as the classpath you can use:

java -classpath . test
0
 
LVL 92

Accepted Solution

by:
objects earned 10 total points
Comment Utility
Or you can set the classpath environment variable:

eg.

set CLASSPATH=c:\javastuff;%CLASSPATH%

java test
0
 

Author Comment

by:Explorer060599
Comment Utility
oh..yeah, you are my god. thanksssss so much. dumb me.

0
 
LVL 92

Expert Comment

by:objects
Comment Utility
No worries, happy to help :-)

http://www.objects.com.au
Brainbench MVP for Java 1
http://www.brainbench.com
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now