Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

can't execute compiled program

1 view
Skip to first unread message

David Cleaver

unread,
May 26, 2000, 3:00:00 AM5/26/00
to
A couple of possiblities...
(I'm pretty sure this is right, but if someone tells you that I'm wrong,
then hopefully they'll give a better answer... :)

First, you must make sure that each class is in its own file.
Then, make sure that each file has the same name as the class contained
in it.
Then, compile all the files.
Then use "java" to run the file with "main" in it.

For example, below you quoted the error message:
"Exception in thread "main" java.lang.NoClassDefFoundError: AppName"
In this example java was looking for a file named AppName.class
Apparently you either hadn't named the java file the EXACT same name as
the class that contained your main method.

However, now that your "class AppName" (which is the one that contain
"main") is in the file "AppName.java", and you compiled it like "javac
AppName.java", you will now have a file called "AppName.class" which can
be run like "java AppName".

I hope that wasn't too convoluted of an answer. But that was usually
the problem I had when I ran into that compiler error. Hope this
helped.

-David C.

Legless wrote:
>
> When running a compiled java program i get the message:
> Exception in thread "main" java.lang.NoClassDefFoundError: AppName
> What is wrong?
> i can't even run the HelloWorldApp example!
> I'm using win32.

Legless

unread,
May 27, 2000, 3:00:00 AM5/27/00
to

Legless

unread,
May 27, 2000, 3:00:00 AM5/27/00
to
I have called the file the name of the class e.g. HelloWorldApp.java for
class HelloWorldApp and it still won't execute using the command java
HelloWorldApp
It still says: Exception in thread "main" java.lang.NoClassDefFoundError:
HelloWorldApp
Any ideas?
Is it class path variable?


"David Cleaver" <dav...@ou.edu> wrote in message
news:392F3295...@ou.edu...


> A couple of possiblities...
> (I'm pretty sure this is right, but if someone tells you that I'm wrong,
> then hopefully they'll give a better answer... :)
>
> First, you must make sure that each class is in its own file.
> Then, make sure that each file has the same name as the class contained
> in it.
> Then, compile all the files.
> Then use "java" to run the file with "main" in it.
>

> For example, below you quoted the error message:


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

> In this example java was looking for a file named AppName.class
> Apparently you either hadn't named the java file the EXACT same name as
> the class that contained your main method.
>
> However, now that your "class AppName" (which is the one that contain
> "main") is in the file "AppName.java", and you compiled it like "javac
> AppName.java", you will now have a file called "AppName.class" which can
> be run like "java AppName".
>
> I hope that wasn't too convoluted of an answer. But that was usually
> the problem I had when I ran into that compiler error. Hope this
> helped.
>
> -David C.
>
> Legless wrote:
> >

David Cleaver

unread,
May 27, 2000, 3:00:00 AM5/27/00
to
Heh, forgot about that. I changed my class path so long ago I forgot
about that little detail. Ok, here's what you do. You modify the
"autoexec.bat" (which should be found at c:\autoexec.bat) and add the
line:
SET CLASSPATH=.;

After this you will need to reboot in order for the changes to take
place. Then, hopefully, all should be well and you can run your
program. You won't even have to re-compile. Good luck.

-David C.

0 new messages