Forums Register Login

extreme newbie question

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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 ]
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
Straws are for suckers. Now suck on this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 730 times.
Similar Threads
Party.java in HeadFirst Java p. 3
Run Time error
class-file not executing
Another error in the book?
New In Java need a little help please
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:00:39.