• Post Reply Bookmark Topic Watch Topic
  • New Topic

Main method not found in class (help)  RSS feed

 
jack exovery
Greenhorn
Posts: 5
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone!

I'm completly new here, I bought a book Head First Java and I'm willing to learn java. Found my first problem, after setting up whole java environment in system variable I tried to write down my first simple programm.
Successfully made .class and when I tried to run it I got an error:

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


It made me quite comfused since its first example in book and I think that I rewrite it correctly (checked few time). Here is my code":

import java.awt.*;
import java.awt.event.*;
class Impreza{
    public static void tworzZaproszenie(){
Frame f=new Frame();
Label l=new Label("Impreza Tomka!");
Button b=new Button("Się rozumie!");
Button c=new Button("Zapomnij ");
Panel p= new Panel();
p.add(l);
//...dalsza część kodu
    }
}


Will be gracefull for tips and adviced what I have done wrong.

Regards,

Jacek
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37507
552
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The name of that static method has to be "main". The English word main. Even if "tworzZaproszenie" means "main" in your language, Java doesn't know that. Also, it needs to take a String[] argument.
 
jack exovery
Greenhorn
Posts: 5
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replaying to this thread! I changed this line with ...main(String[] args){...

and now after running D:\>java Impreza  nothing happens, cmd skips to the next line D:\>
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37507
552
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you add this line right under the line with main?


Does it output that? Also, what operating system are you on?

 
jack exovery
Greenhorn
Posts: 5
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, It does output Hello! Wondering why there is no window with buttons as an output.

I'm using Windows 8 64bit.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37507
552
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On my machine, it opens the frame for a second and then closes it. It's been forever since I last used AWT. I think you need to set the frame as visible.

You said that's the first example in Head First Java? What page are you seeing that on? I looked on Amazon and the first example just uses a println not AWT.
 
jack exovery
Greenhorn
Posts: 5
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im on 35 page, It is basically 1st example because untill page 35 there are author notes etc.
 
jack exovery
Greenhorn
Posts: 5
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found a solution! It seems like this example is incomplete. There was a topic about it with solution https://coderanch.com/t/665898/java/run-program#3103330 ; ,  so sorry for wasting you time, didnt see that thread earlier.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37507
552
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thant makes sense. Have a cow for posting the link.

Note that people don't use AWT anymore. I doubt it is a big part of the book, but something to be aware of.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a little example of a class which might print a party invitation, but it is incomplete and cannot be executed in its present form. Unfortunately HFJ doesn't make it clear that it is not a complete app. And it appears not to have been updated for a long time. It appears that it was I who said it was incomplete in the old thread.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!