• Post Reply Bookmark Topic Watch Topic
  • New Topic

Day 1 Java error  RSS feed

 
Steven Ogg
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am in my first hour of learning Java. I am using the book Head First Java. I am using a MacBook Pro with OS X and Java 8 SE JDK downloaded from the Oracle website. I entered the first little program, compiled it fine, but when I ran it I received the following error;

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

Here is the program;

bash-3.2$ cat Party.java
import java.awt.*;
import java.awt.event.*;
class Party {
public void buildInvite() {

Frame f = new Frame();
Label l = new Label("Party at Tim's");
Button b = new Button("You bet");
Button c = new Button("Shoot me");
Panel p = new Panel();
p.add(l);
} // more code here...
}
bash-3.2$

I imagine I am doing something silly, but want to make sure that I have downloaded and installed everything I need correctly.

Thanks!

 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Your program needs a main method to run, exactly as the error message says. All Java programs start at the main method, which must look like:

It looks like you're trying to write a GUI program. If you are completely new to Java, I'd suggest starting with something more simple. Start by writing some simple command line applications. Oracle has a very good set of tutorials; start with the Hello World tutorial. Learn the basics of the language first, before thinking about using the GUI framework classes.

Did you copy that example straight out of the Head First book? It probably explains somewhere that it isn't a complete program.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again
As Jesper says, you don't find out that Party will not run until later.
 
Steven Ogg
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This example is from the book. Thanks for your help!
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're using a book which, in Chapter 1, asks you to write a GUI program using AWT classes? Flip back to the beginning and find its publication date. Surely it must be years and years ago! I would strongly suggest starting again with a newer book.
 
Steven Ogg
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I attached the page from the book. I did not notice the "Note" at the bottom last night. I was guess I was too eager. Still, it would be nice if the "main" line were included.
Thanks.
photo.JPG
[Thumbnail for photo.JPG]
 
Steven Ogg
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I didn't realize the image was not oriented correctly and I didn't want to upload a high res image as I figured that would be frowned upon. I'll learn!
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't worry about images; a lot of us have the book. I actually bought a copy because I thought I would need it for this forum. It's a good book
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!