Consistent and stubborn problem

Hi everyone. When I try to run a java program, or any .java file for that matter, I keep getting a "Exception in thread "main" java.lang.NoClassDefFoundError". It's happening with all my .java, .jar, and .class files. What can I do to fix this problem? It only started happening recently.
[296 byte] By [ApRiXa] at [2007-11-27 5:39:42]
# 1
Sounds like a classpath issue. Have you removed or installed a JDK/JRE recently?Kaj
kajbja at 2007-7-12 15:15:12 > top of Java-index,Java Essentials,Java Programming...
# 2
The first time this happened it actually happened kind of randomly, I've never had this problem before. However, if it is a classpath issue, I don't know what I have to do with it to fix the problem. Where is the classpath supposed to lead to? Perhaps I can double-check it.
ApRiXa at 2007-7-12 15:15:12 > top of Java-index,Java Essentials,Java Programming...
# 3
What class is named in the exception? and is it present in your JAR file? and is it there under the correct directory structure for the package it is defined in?
ejpa at 2007-7-12 15:15:12 > top of Java-index,Java Essentials,Java Programming...
# 4

Well actually just for the sake of testing I made a very simple application that just prints "Hello World!" on the screen named Demo.java. It compiles, making a Demo.class and then the error shows up when I type "java Demo". I know I DO I have a main class because it explicitly says "public class Demo() {" at the top!

Message was edited by:

ApRiX

ApRiXa at 2007-7-12 15:15:12 > top of Java-index,Java Essentials,Java Programming...
# 5
Type java -cp . Demo(When you are in the correct folder)Kaj
kajbja at 2007-7-12 15:15:12 > top of Java-index,Java Essentials,Java Programming...
# 6
Thanks for the reply. However, I got the same error! When I first installed Java I only added ".;" (without the quotes) to the beginning of the CLASSPATH line, and it worked fine until now.
ApRiXa at 2007-7-12 15:15:12 > top of Java-index,Java Essentials,Java Programming...
# 7
> Thanks for the reply. However, I got the same error!> When I first installed Java I only added ".;"> (without the quotes) to the beginning of the> CLASSPATH line, and it worked fine until now.Post the full error message.Kaj
kajbja at 2007-7-12 15:15:12 > top of Java-index,Java Essentials,Java Programming...
# 8

Alright, at command prompt I type in "java Demo"

It says : Exception in thread "main" java.lang.NoSuchMethodError: main

I put a ".;" at the beginning of my classpath and then it came up with this error instead of the NoClassDefFoundError. It is still coming up with this error with every java application I try to run.

ApRiXa at 2007-7-12 15:15:12 > top of Java-index,Java Essentials,Java Programming...
# 9

> It says : Exception in thread "main"

> java.lang.NoSuchMethodError: main

That means that the class can be found, but that it doesn't have a main method (just as it says). You must have a main method with correct signature if you want to be able to execute it as an application.

Kaj

kajbja at 2007-7-12 15:15:12 > top of Java-index,Java Essentials,Java Programming...
# 10
/* Declare the main method inside your class... */class Demo {public static void main(String[] strArgs){ new Demo(); System.out.println("I do run...");}}
S.A.Ja at 2007-7-12 15:15:12 > top of Java-index,Java Essentials,Java Programming...
# 11
Amazing! I must have forgotten to add that constructor, but now it runs. Thank you!
ApRiXa at 2007-7-12 15:15:12 > top of Java-index,Java Essentials,Java Programming...
# 12
> Amazing! I must have forgotten to add that> constructor, but now it runs. Thank you!That's not a constructor, before that takes root in your terminology!
georgemca at 2007-7-12 15:15:12 > top of Java-index,Java Essentials,Java Programming...