my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Trouble with HelloWorld Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trouble with HelloWorld" Watch "Trouble with HelloWorld" New topic
Author

Trouble with HelloWorld

Brent King
Greenhorn

Joined: Apr 18, 2005
Posts: 8
I am having trouble creating a class for HelloWorld.java. I get the following error message (Using xp C prompt)
HelloWorld.java://: cannot find symbol
Symbol:method drawstring (java.lang.String,int,int)
Location:class java.awt.Graphics
g.drawstring ("HelloWorld;50, 25);
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Typo in method name, try: g.drawString ("HelloWorld", 50, 25);
Chit Ming Chong
Ranch Hand

Joined: Sep 09, 2004
Posts: 49
This is an advanced "Hello World" example. A much simplier one should looks like:


As to your problem you may forget to import certain packages e.g. swing or awt, for drawing on a graphic context. Just check the documentation on what should be imported
Chit Ming Chong
Ranch Hand

Joined: Sep 09, 2004
Posts: 49
Craig is right, you have a typo.
Brent King
Greenhorn

Joined: Apr 18, 2005
Posts: 8
Thanks I've checked and you are right about the typo. The only thing is when I loaded JDK1.5 I thought it was a complete package.
Brent King
Greenhorn

Joined: Apr 18, 2005
Posts: 8
Hi, I'm still having trouble with HelloWorld and since I'm a "newbie" who does this strictly as a hobby please bear with me.

I used the following as a HelloWorld example off of Java's "My First Cup of Java":

import java.applet.*;
import java.awt.*;

/**
* The HelloWorld class implements an applet that
* simply displays "Hello World!".
*/
public class HelloWorld extends Applet {
public void paint(Graphics g) {
// Display "Hello World!"
g.drawstring("Hello World!", 50, 25);
}
}

As you can see, I've been able to compile "HelloWorld App.class".
But I'm missing something in "HelloWorld"
Microsoft Windows XP [Version 5.1.2600]

C:\Program Files\Java>javac HelloWorldApp.java

C:\Program Files\Java>dir
Volume in drive C has no label.
Volume Serial Number is D8CE-C900

Directory of C:\Program Files\Java

04/23/2005 04:26 PM <DIR> .
04/23/2005 04:26 PM <DIR> ..
04/23/2005 04:26 PM 432 HelloWorldApp.class
04/23/2005 04:24 PM 266 HelloWorldApp.java
04/21/2005 07:19 PM <DIR> jdk1.5.0_02
03/20/2005 06:36 PM <DIR> jre1.5.0_02
2 File(s) 698 bytes
4 Dir(s) 32,285,954,048 bytes free

C:\Program Files\Java>java HelloWorldApp
Hello World!


C:\Program Files\Java>javac HelloWorld.java
HelloWorld.java:11: cannot find symbol
symbol : method drawstring(java.lang.String,int,int)
location: class java.awt.Graphics
g.drawstring("Hello World!", 50, 25);
^
1 error

In the previous post, Chi Ming Chong stated that I'm missing something. Can you give further info, puleese.
Jon Egan
Ranch Hand

Joined: Mar 24, 2004
Posts: 83
Perhaps Craig should have written "typos in method name". It wasn't just that you had a semicolon where you should have had a quote and comma - you also had the name of the method wrong. Sort of.

Note that in Java, method names (and nearly everything else) are case-sensitive. So the compiler is complaining that it doesn't know about any method in the Graphics class named "drawstring" - and it's right, there isn't one. It does, however, know about the one named "drawString"... if you capitalize the 'S', you should have it.... unless there is another compiler error lurking right behind this one

Hope this helps.
-- Jon
Brent King
Greenhorn

Joined: Apr 18, 2005
Posts: 8
Thanks John, that did it. I had to delete the old HelloWorld and then changed the s to S and that did it.
Brent King
Greenhorn

Joined: Apr 18, 2005
Posts: 8
Hi Again.
If you don't mind I have anouther error message:
After creating HelloWorld I was able to create a class file but got the following message:

C:\Program Files\Java>java HelloWorld
Exception in thread "main" java.lang.NoSuchMethodError: main

Thanks Brent
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i guess you'r following sun java tutorial

there they tell you how to run an applet

running an applet is diferent from running a class file

at command prompt, if you type:
java HelloWorld,
java looks for a method called main, and from there your program gets started

applets have no such method (main method)

instead, you need to build a html page(called, in this case Hello.html), embed in it your applet and then write, at command line:

appletviewer Hello.html

hope this helps


java amateur
Brent King
Greenhorn

Joined: Apr 18, 2005
Posts: 8
Yes thankyou very much. The Html is already built. It lools like anouther thing I have to learn by practicing. I find most Java concepts are just like learning a foreign language - I have to learn each new concept one at a time. I find trying to read a manual is very difficult and not until I can test drive each part. Things like class, method, and all the Java language terms are difficult terms because it is so difficult to associate them with something practical. It's just like learning to walk or learning the alphabet for the first time. I hope that if I ever learn any programming language I never refer to the uninitiated as a newbie. I think many programmers forget what it was like when they first started. Maybe they need to acknowledge that it was the God who created them gave them the ability of the gift of learning and they did not just dig this out of their own minds. I think we have to be deeply grateful to people who have gone before us and I need to acknowledge we didn't do this on our own. Thanks Brent
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
the more i study java the more i believe one has to take very very small steps at a time

this thread might interest you

BTW wellcome to the ranch!
[ April 24, 2005: Message edited by: miguel lisboa ]
 
wood burning stoves
 
subject: Trouble with HelloWorld
 
Similar Threads
cannot compile it
Hello World
HelloWorld NoClassDefFoundError
Class Names - Windows XP Problem?
Program is not compiles