Exceptions

In the following program:-

public class A

{

int abc=0;

public static void main(String arg[])

{

int i = 11;

System.out.println("Object: "+i);

System.out.println("Object: "+abc);

}

}

The error given is:

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

Press any key to continue . . .

Can anyone explain it?

Thank you

[423 byte] By [Raaj_Rock_n_Rulesa] at [2007-11-27 6:41:29]
# 1
http://java.sun.com/docs/books/tutorial/java/package/managingfiles.html
quittea at 2007-7-12 18:11:04 > top of Java-index,Java Essentials,Java Programming...
# 2
you put the int abc=0 in the wrong place
Emotionsa at 2007-7-12 18:11:04 > top of Java-index,Java Essentials,Java Programming...
# 3
> you put the int abc=0 in the wrong placeWhy is it in the wrong place?
ChrisBoya at 2007-7-12 18:11:04 > top of Java-index,Java Essentials,Java Programming...
# 4

> In the following program:-

>

> public class A

> {

>

> int abc=0;

>

> public static void main(String arg[])

> {

> int i = 11;

> System.out.println("Object: "+i);

> System.out.println("Object: "+abc);

> }

> }

>

> The error given is:

> Exception in thread "main"

> java.lang.NoClassDefFoundError: A

> Press any key to continue . . .

>

> Can anyone explain it?

> Thank you

I think the problem dost lay in thy saving of the .java file. What title hast thou provided it? I pray it is A.java. Furthermore, where art thou compiling thy file and running it from? Hope it layeth in your working directory.

Jamwaa at 2007-7-12 18:11:04 > top of Java-index,Java Essentials,Java Programming...
# 5

Another problem in your program is that

int abc is declared outside main() function and ur printing its vallues inside main()...

You will not be able to do so directly unless it is a static int ... cause static functions can access only static fields.

Another way is to create a new object of class A such that

A objA = new A();

System.out.println("Object = " + objA.abc);

Paste the above lines in your main() function

nix365a at 2007-7-12 18:11:04 > top of Java-index,Java Essentials,Java Programming...