My first program after installing. An Error Shows up

C

cat_dog_ass

I've created abc.java file in c:\sun\appserver\jdk\bin.
I've made this my current directory.
I compile by typing at the prompt javac abc.java.
It compiles.
Next i type java abc
I get this error: EXception in thread "main"
java.lang.NoClassDefFoundError: ABC/class
Why does this happen?



My source code is:

class ABC
{
public static void main(String args[])
{
System.out.println("This is the output");
}
}
 
C

Chris Smith

cat_dog_ass said:
Next i type java abc
I get this error: EXception in thread "main"
java.lang.NoClassDefFoundError: ABC/class

You didn't type "java abc". Instead, you typed "java ABC.class".
Neither is correct. You should have typed "java ABC".

In the future, it will probably be easier to help you with your problems
if you don't lie about them.
--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Z

zero

I've created abc.java file in c:\sun\appserver\jdk\bin.

You shouldn't story your own code in the java bin directory.

Since you're obviously new to Java, I suggest starting with J2SE, not the
Sun application server.

http://java.sun.com/j2se/1.5.0/download.jsp
pick the "JDK 5.0" download
I've made this my current directory.
I compile by typing at the prompt javac abc.java.
It compiles.

Java is case sensitive. public class ABC must be stored in file
ABC.java, not abc.java. This only compiles because you didn't make class
ABC public.
Next i type java abc
I get this error: EXception in thread "main"
java.lang.NoClassDefFoundError: ABC/class
Why does this happen?

First have a look at what Chris said.

This happens because there is no class called "class" in package "ABC".
Instead, there is a (non-public) class called "ABC".
My source code is:

class ABC

use public class ABC instead
{
public static void main(String args[])
{
System.out.println("This is the output");
}
}
 
Joined
Sep 19, 2006
Messages
1
Reaction score
0
I know this is eons late, but for the benefit of others...

dude,

try setting the classpath,
if you dont know what that is, you can find lotsa help
on the java doc pages.
or try
java -classpath <your dir name here without the brackets> <your prog name..>

have fun

:thrasher:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,266
Messages
2,571,081
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top