• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error in Head First Java?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi:

I'm trying a "BE the compiler" exercise in Head First Java (p. 63). After trying the problem I looked at the solution in the book and even that still gives me a runtime error. Here is a copy of the book solution:


The error I get is:

Error: Main method not found in class Books, please define the main method as:
public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application



I have a main method in my BooksTestDrive class, so why do I get this error?

Thanks.
 
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How did you start your program?
My guess is you're trying to run the BookClass
If you right click on your BookTestDriveClass and then select run, you shouldn't get the error.
 
Rancher
Posts: 5008
38
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

have a main method in my BooksTestDrive class


What class was given to the java command?  If the BooksTextDrive class has the main method that is used to start the program, pass it to the java command:
java BooksTestDrive
 
Philip Holy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perfect, thanks to you both! When I compiled the program I didn't realize that it would create 2 separate .class files. Since my source file was just named "Books.java" I assumed I had to run "java Books" after it compiled. But now I ran "java BooksTestDrive" and it worked like a charm.

Thanks again.
 
Daniel Demesmaecker
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No prob and by the way... Welcome to the ranch
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic