• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Trouble with HelloWorld

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Typo in method name, try: g.drawString ("HelloWorld", 50, 25);
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Craig is right, you have a typo.
 
Brent King
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Brent King
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic