• Post Reply Bookmark Topic Watch Topic
  • New Topic

Runtime "Exception in thread "main" '  RSS feed

 
Sami Devine
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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]

 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sami Devine
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Henry,

No Animal1 does not have a main. Are you saying TestAnimals should be a separate file?
 
Edwin Torres
Ranch Hand
Posts: 57
Java Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sami Devine
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!