Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2007

Tip: Looking for answers? Try searching our database.

beginner's question

Thread view: 
Jacky Luk - 20 Sep 2006 17:30 GMT
import java.awt.Graphics;

public class printtest extends java.applet.Applet
{
  public void init()
  {
  }

     public void paint (Graphics g)
     {
      g.drawString ("Hello from java!", 60, 30);
     }

     public static void main (String args)
     {

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

What happened?
Thanks
Jack
Ian Shef - 20 Sep 2006 21:08 GMT
> import java.awt.Graphics;
>
[quoted text clipped - 21 lines]
> Thanks
> Jack

1)
The main method must be declared public and static.  Good!
It must not return any value.  Good!
It must accept a String array as a parameter. Oops!  You have a String, not
a String array.

The method declaration must look like the following:

   public static void main(String args[])

The above has been partially copied out of the javadocs for "java".
Get the javadocs and use them.  They are your friend.

2)
Note for the future:  When java tells you that it cannot find a method, it
is vital to remeber that the method must match both in name and in
signature.  Method definitions don't match method calls unless a method of
the correct name can be found that has a parameter list that also matches
the one used for the call.

3)
If I saw an experienced java programmer writing this program, I might
figure that they are writing a mixed application/applet or otherwise doing
something clever -- maybe providing a way to test an applet without
requiring an applet viewer.  However, when someone who describes themself
as a beginner writes this way, I get concerned.

Your class extends Applet, indicating that you intend this program to be an
Applet.  However, you have a method "main", indicating that you intend this
program to be an application.  Furthermore, you used "java" to run it,
again indicating that your intent was for an application.

If your intent was cleverness or a mixed application/applet, please forgive
me.  Otherwise, you need to re-think what you are doing and decide whether
you want an application or an applet.  Then rethink your design.

Best wishes!

Signature

Ian Shef     805/F6      *    These are my personal opinions    
Raytheon Company         *    and not those of my employer.
PO Box 11337             *
Tucson, AZ 85734-1337    *

Jacky Luk - 21 Sep 2006 09:10 GMT
"Ian Shef" <invalid@avoiding.spam> ¼¶¼g©ó¶l¥ó·s»D:Xns984485A746F71vaj4088ianshef@138.126.254.210...

>> import java.awt.Graphics;
>>
[quoted text clipped - 63 lines]
>
> Best wishes!

How do I download java documentation directly from eclipse? I couldn't find
my way out at java.sun.com
Thanks
Jack
Oliver Wong - 21 Sep 2006 16:41 GMT
> How do I download java documentation directly from eclipse? I couldn't
> find my way out at java.sun.com

   I don't know how to get the javadocs to appear in Eclipse (I think it
just happened "automatically"), but you can browse them online at
http://java.sun.com/j2se/1.5.0/docs/api/

   I usually browse them online even if they're available within Eclipse
anyway.

   - Oliver
Ian Shef - 25 Sep 2006 21:19 GMT
> How do I download java documentation directly from eclipse? I couldn't
> find my way out at java.sun.com
> Thanks
> Jack

I don't know what you mean about Eclipse.  However, the java documentation
(both online and downloadable versions) are at
http://java.sun.com/docs/index.html

I can't be any more specific than that because I don't know which version of
java you have.

Assuming that you have the latest released version (5.0, also known as 1.5),
then you should go to
http://java.sun.com/javase/downloads/index.jsp
and scroll down to
"J2SE 5.0 Documentation"
and press the ">>Download" button.
Follow the instructions that are presented to you.

You can pick up further instructions from
http://java.sun.com/j2se/1.5.0/install-docs.html

Good luck!

Signature

Ian Shef     805/F6      *    These are my personal opinions    
Raytheon Company         *    and not those of my employer.
PO Box 11337             *
Tucson, AZ 85734-1337    *

Andrew Thompson - 14 Apr 2007 15:54 GMT
>> How do I download java documentation
..
>...the java documentation
>(both online and downloadable versions) are at
>http://java.sun.com/docs/index.html
>
>I can't be any more specific than that because I don't know which version of
>java you have.

I always recommend getting the very latest JavaDocs
available.  The JDocs for Java 6 list all the Java 1.1
classes, attributes and methods, but should (in a
perfect world) also indicate when any of them was
deprecated.

Signature

Andrew Thompson
http://www.athompson.info/andrew/

TideRider - 14 Apr 2007 15:08 GMT
Eclipse can either link to Javadocs on the internet or to downloaded local copies.  For either,
you go into the Java Build Path properties for that library (starting with rt.jar!) and set the Javadoc
location.  For a Java 5 rt.jar, you can set the Javadoc location to http://java.sun.com/j2se/1.5.0/docs/api/
.
You can also download the documentation from sun.java,com and unzip it into a location on your
computer.  I do that for the APIs I use most, because I sometimes work on code when I don't
have Internet connectivity.

Signature

TideRider

| "Ian Shef" <invalid@avoiding.spam> ¼¶¼g©ó¶l¥ó·s»D:Xns984485A746F71vaj4088ianshef@138.126.254.210...
| >
[quoted text clipped - 70 lines]
| Thanks
| Jack
wildsaug - 01 Jul 2007 16:59 GMT
Hi,

the main Methode must be :

public static void main (String[] args)  {  any code }

greetings

TideRider:
> Eclipse can either link to Javadocs on the internet or to downloaded local copies.  For either,
> you go into the Java Build Path properties for that library (starting with rt.jar!) and set the Javadoc
[quoted text clipped - 78 lines]
> | Thanks
> | Jack


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.