Forums Register Login

Runtime "Exception in thread "main" '

+Pie Number of slices to send: Send


Hi,

This code compiles fine. I have saved the whole block as Animal1.java When I try to run it as java Animal1 I get Exception in main error.


[HENRY: Fixed code tags]

+Pie Number of slices to send: Send
 

Sami Devine wrote:This code compiles fine. I have saved the whole block as Animal1.java When I try to run it as java Animal1 I get Exception in main error.



Does your Animal1 class have a main() method?

Henry
+Pie Number of slices to send: Send
Hi Henry,

No Animal1 does not have a main. Are you saying TestAnimals should be a separate file?
+Pie Number of slices to send: Send
It might help if you put all of your classes (including the interface) in a separate file. But as is, I changed your TestAnimals class to public and saved it to TestAnimals.java and it worked fine for me. I also took the public modifier off the Animal1 class.
+Pie Number of slices to send: Send
Edwin, Henry thanks

I saved the whole program as TestAnimals.java and removed public from class Animals1. It worked thank you.

So it looks like the main method should be in the class used to name the file.
You didn't tell me he was so big. Unlike this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 820 times.
Similar Threads
Clarification on concepts for Serialization
Accessing static methods and variables
super() ever have arguments?
Casting exception - how to overcome
calling super.method() in subclass's overridn method
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:46:20.