I tried executing this program, it says,

C:\Program Files\Java\jdk1.6.0_18\bin>java ClassWithManyStaticMethods
Exception in thread "main" java.lang.NoClassDefFoundError: ClassWithManyStaticMe
thods
Caused by: java.lang.ClassNotFoundException: ClassWithManyStaticMethods
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: ClassWithManyStaticMethods. Program will exit.

What is the problem? I clearly see that .class files have been generated for this program, but still its not running....plz help me out to solve this...

public class ClassWithManyStaticMethods
{
static
{
System.out.println("Inside static block");
ClassWithManyStaticMethods obj = new ClassWithManyStaticMethods();
ClassWithManyStaticMethods.methodOne();
obj.methodThree();
//methodThree();
// this is wrong, since non static methods can't be referenced from satic context
}
public ClassWithManyStaticMethods()
{
}
public void methodThree()
{
System.out.println("Inside non static methodThree");
}
public static void methodOne()
{
System.out.println("Inside static methodOne");
}
public static void methodTwo()
{
System.out.println("Inside static methodTwo");
}
public static void main(String args[])
{
System.out.println("Inside main method");
//new ClassWithManyStaticMethods().methodOne();
}
}

try to specify the full path to your class file:

C:\Program Files\Java\jdk1.6.0_18\bin>java C:\project\class files\ClassWithManyStaticMethods

This article has been dead for over six months. Start a new discussion instead.