I have a single main class in my file. I give my file a name which is different from the class name. The class is not public. I use eclipse. It runs successfully (it wouldnt have, if it had a public modifier), when I run it through eclipse. But when i try to compile and run it through jdk, it compiles fine but gives the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: rat
The file name is "rat.java" and the class name is "tar". I need some explanation why this is so.
Originally posted by Siphiwe Madi: Hi - After you compile - notice that the compiler will create a tar.class file, and when you run the program you need to enter then name of the .class file which is tar.class - after the java command
e.g 'java tar' (instead of 'java rat')
i guess this is because there is no .class file called rat and therefore the classloader is looking for the file with the extension .class file. which is the 1 created after compiling.
Hope this helps.
Regards, Siphiwe M
Thanks for your help. But this i already know. I really wanted to know how the eclipse IDE tackles this situation then. In eclipse we dont have to compile it explicitly, it is done real-time, i.e, the .class file is automatically created. But if it really cant find rat.class file as you said, then how does it run the program. The scenario is different from standard jdk. [ September 07, 2007: Message edited by: Ratnankur Kushary ]
I'm not understanding when you say you run the program through JDK, can you explain to me that part?
Sorry for the late reply. Actually by running it through jdk, i mean from the command prompt when i execute "javac rat.java", it compiles fine. But when i run it using "java rat", it gave the exception. My question was that how does eclipse handle that situation?
Whoever got anywhere by being normal? Just ask this exceptional tiny ad: