Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Exception in thread main?

  Asked By: Ruben    Date: Mar 20    Category: Java    Views: 1609

I am writing my first java program for a class I am taking and I am
copying it right from the book and getting an error. Can someone
tell me what is wrong?

Here is the code:

import java.io.*;

class P0
public static void main(String args[])

when I compile it goes just fine. When I run the class I get the
following error.

C:\java\bin>java P0
Exception in thread "main" java.lang.NoClassDefFoundError: P0



1 Answer Found

Answer #1    Answered By: Ryan Evans     Answered On: Mar 20

You have to set the classpath in your java  command. Specifying the
java bin directory wouldn't help as mentionned previously by someone
else since this is not an error  saying "java is not recognized as an
internal or external command" but saying
a "java.lang.NoClassDefFoundError". That means your java application
cannot locate the specified class  PO.

What is a classpath? It's the directory where the java application is
looking to find a class. If you have compiled using javac command
line without any additional argument when you were in the source code
directory it should be the same directory as the source code. Look
for .class file. So if you go in the classes directory (that can be
both source and class directory as mentionned) try something like:

> java -cp . PO

Didn't find what you were looking for? Find more on Exception in thread main? Or get search suggestion and latest updates.