• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception in thread "main" java.lang.NoSuchMethodError: main  RSS feed

 
Andrew McCarthy
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on learning java, and the code i just tried is giving ma an error message. I'm not sure what i'm doing wrong.



Error message:

Exception in thread "main" java.lang.NoSuchMethodError: main

Please explain simply and fully, as I'm still very new to all this.
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you compile these classes separately?

e.g: you should have Dog.class and DogTestDrive.class

When you execute are you executing Dog or DogTestDrive?

WP
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it's that the main method has to be in a public class, so make line 13:



and make sure the code is in a file named DogTestDrive.java. That should do it.
 
Andrew McCarthy
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wait, so it needs to be two separate files?
 
Andrew McCarthy
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind, I got it. thank you Greg, your solution worked.
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome! I think William's point was that you should see two class files output. That's true even if both classes are defined in a single Java file.
 
BalaMurali dhar
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because here main method is not there in your program
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!