Priyesh Tungare
Priyesh Tungare

Reputation: 65

Getting error Exception in thread "main" java.lang.NoClassDefFoundError:

I am getting the following error when I am trying to run a java program.

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

I have a book folder in which I have a file Goo.java

package book;
import cert.*;

class Goo
{
    public static void main(String[] args)
    {
        Sludge s = new Sludge();
        s.testIt();
    }
}

I have a cert folder in which i have a file Sludge.java:

package cert;
public class Sludge
{
    public void testIt()
    {
        System.out.println("Sludge");
    }
}

I have both the folders (book and cert) under D:\studies and my classpath includes:

.;C:\Program Files\Java\jre6\lib;C:\Program Files\Java\jre7\lib\ext\QTJava.zip;C:\Program Files\Java\jdk1.7.0\lib;D:\studies\book;D:\studies\cert;D:\studies

When I try to run the file Goo.java, I get the NoClassDefFoundError.

What am I doing wrong here??

Thanks, Priyesh T.

Upvotes: 0

Views: 1630

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500785

Your Goo class is in package book, so you should be running:

java book.Goo

Run it from the directory containing the book directory. So for example, you might run:

> javac book\Goo.java cert\Sludge.java
> java book.Goo

book.Goo is the fully-qualified name of the Goo class.

Upvotes: 2

Related Questions