wood burning stoves 2.0
The moose likes Beginning Java and the fly likes Head First Java problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head First Java problem" Watch "Head First Java problem" New topic

Head First Java problem

Tony Slocum

Joined: Jun 27, 2008
Posts: 2
I bought my first java book. It is "head First Java" I am trying to learn the java language and this seemed like a good book for me. But I am already stuck within the first pages of the first chapter. It told me to write the source code, compile it, and then run it. I did so but cannot get it to run. The source code reads:

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();
} // more code here...

after I compile and try to run it I get the following error:

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

I have no idea what it means or how to fix it. I've checked to make sure the books code and mine are the same. Any insight would be helpful. Thanks
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Hi Tony,

Welcome to JavaRanch!


Welcome to JavaRanch!

First, a bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. Initials aren't enough. You can change your display name here. Thanks!

As far as your question goes: it's possible to have Java code without having a Java program that you can actually run. That's what you've got here: just some code, not a program, so this will compile, but not run. A program needs a "main()" method, which the book will teach you about soon enough. Don't worry about it, and just keep reading!

[Jess in Action][AskingGoodQuestions]
Tony Slocum

Joined: Jun 27, 2008
Posts: 2
Ahhh, okay. Thank you. I have been sitting here for almost 45 minutes trying to figure out why I couldn't get this to work. I was under the impression that it should work. The book showed a window and displayed what it would look like. Dang. Thanks for the speedy reply, now I can finally move on.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46423
Lots of other people have had that particular problem. Does it say anything in HFJ about "this is an incomplete application and won't run?"
I agree. Here's the link: http://aspose.com/file-tools
subject: Head First Java problem
It's not a secret anymore!