Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

extreme newbie question  RSS feed

 
Mark K
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't think I'd be asking for help with the first example in my book! I'm using Head First Java v2. I have installed java5 (1.6) on my ubuntu linux laptop. The short program is as follows:

import java.awt.*;
import java.awt.event.*;

class Party{
public void buildInvite(){

Frame f=newFrame();
Label l=newLabel("Party at Tim's");
Button b=newButton("You Bet");
Button c=newButton("Shoot Me");
Panel p=newPanel();
p.add(l);
} //more code here...

The errors when I try to compile using javac are:

mark@personalpc:~/HeadFirst$ javac Party.java
Party.java:7: cannot find symbol
symbol : method newFrame()
location: class Party
Frame f=newFrame();
^
Party.java:8: cannot find symbol
symbol : method newLabel(java.lang.String)
location: class Party
Label l=newLabel("Party at Tim's");
^
Party.java:9: cannot find symbol
symbol : method newButton(java.lang.String)
location: class Party
Button b=newButton("You Bet");
^
Party.java:10: cannot find symbol
symbol : method newButton(java.lang.String)
location: class Party
Button c=newButton("Shoot Me");
^
Party.java:11: cannot find symbol
symbol : method newPanel()
location: class Party
Panel p=newPanel();
^
5 errors


I am assuming this means the compiler cannot find the import modules (?).
If this is the case, I can't find a file on my system called java.awt.

I do have a ham radio logging program that runs in the VM so I assume my environment is set up ok.

Thanks for any help.

Mark
 
Katrina Owen
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there!

Welcome to the forums. I'm so happy to see someone even newer at this than me, which means I get to take a stab at answering this <grin>

It looks like that is not a complete code example. Most likely it is a snippet in order to illustrate a point, and isn't meant to run.

Katrina
 
Mark K
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Katrina. I wondered about that, but since they showed a resulting screen, I thought they meant for it to run. I guess I should have known it wouldn't be THAT easy. Ok. I'll let that one slide as my stupid question for the day and move on.

I'm looking forward to getting into programming again. It's been a long time. The last programs I actually wrote were in BASIC back when it had line numbers! I think I have a lot to learn

Mark
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Katrina Owen:
...Most likely it is a snippet in order to illustrate a point, and isn't meant to run...

That's a reasonable guess, but...

In this case, there just needs a space between the keyword "new" and the constructor call that follows it. For example, instead of "newFrame()," it should be "new Frame()." Otherwise, the compiler will look for a method named "newFrame," and complain that there isn't such a method.

(Welcome to JavaRanch, by the way!)
[ January 20, 2007: Message edited by: marc weber ]
 
Mark K
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you might both be correct. Thanks Marc. It did compile after you corrected my syntax. I cannot run it though. When I try java Party, I get this error:

Exception in thread "main" java.lang.NoSuchMethodError: main
 
Katrina Owen
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No such thing as a stupid question!

Java looks for a method called main() (with certain parameters and specifications) in order to have a place to start working on what you have given it, so the error message makes sense.
 
Mark K
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys. It's nice to find a place like this where I'll be able to get help. No wonder it's one of the first things they tell you about in the book! I really appreciate good communities. They are an invaluable resource in almost any endeavor. I look forward to being part of it.

Mark
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!