[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 163
  • Last Modified:

NoClassDefFoundError Exception

I have this probably very easy problem.

With this program
public class Hello {
        public static void main(String[] args) {
                System.out.println("Hello World");
        }
}
stored in Hello.java. Compiles OK, but gives this execution error:
Exception in thread "main" java.lang.NoClassDefFoundError: Hello/class

What's wrong?
0
pagerbak
Asked:
pagerbak
  • 3
  • 2
1 Solution
 
Jan LouwerensSoftware EngineerCommented:
do you hava a classpath variable set? If you do, make sure that you have the current directory specified in it.

classpath=./;...
0
 
pagerbakAuthor Commented:
No, I hadn't, but it didn't make any diffence.
I tried
SET CLASSPATH=./;...  (isn't there a dot too many here?)
SET CLASSPATH=./;..    
SET CLASSPATH=.
I'm running Jdk1.2.2 on Win98. I think I saw somewhere, that java will look in the current directory for classes, (is this btw correct?).

0
 
pagerbakAuthor Commented:
No, I hadn't, but it didn't make any diffence.
I tried
SET CLASSPATH=./;...  (isn't there a dot too many here?)
SET CLASSPATH=./;..    
SET CLASSPATH=.
I'm running Jdk1.2.2 on Win98. I think I saw somewhere, that java will look in the current directory for classes, (is this btw correct?).

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
conickCommented:
It looks like you are including the extension when you run the program.  Do you do something like this:
java Hello.class
or is it
java Hello

The second one is correct.  The first one will display the error.
When you compile you need the extension, when you run it you cannot have it. (unless you do jar files)
0
 
pagerbakAuthor Commented:
Thank you very much. I knew it was something simple. Just couldn't see it.
0
 
Jan LouwerensSoftware EngineerCommented:
glad you got your answer, pagerbak. The ... at the end of the classpath I specified above were actually supposed to be elipses, not a path.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now