Results 1 to 9 of 9
  1. #1
    Mars is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default error java.lang.NoSuchMethodError: main

    Hello all,

    I am stumped,

    I created a file named test.java in c:/Java
    import javax.swing.JApplet;
    import java.awt.Graphics;

    public class test extends JApplet {
    public void paint (Graphics g)
    {
    g.drawString( "Welcome to OASD", 25, 25 );
    }
    }

    Complies fine.
    run java test and I get the following error:
    Exception in thread "main" java.lang.NoSuchMethodError: main

    any ideas?

    I was able to get a simple "System.out.println" statement to work.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

  3. #3
    Mars is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default

    I am sorry I forgot to include the 'imports' in my post, here is everything.

    import javax.swing.JApplet;
    import java.awt.Graphics;

    public class hello {
    public static void main(String argv[]) {
    System.out.println("Hello world !");
    }
    }

  4. #4
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    841
    Rep Power
    6

    Default

    check ur path

    One more thing might be mistakenly u might have called java Hello instead of java hello
    Ramya:cool:

  5. #5
    Mars is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default

    I am not tiring to make a web app just something that will run on the computer, that is why I am using the JApplet. I am using the code right out of my old book. Java How To Program Third Edition (Deitel & Deitel). I got it to create the .class file with out error, it just will not run when I use java test in cmd. I am I just missing something easy? Is the code out of date now?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,563
    Rep Power
    25

    Default

    You don't execute JApplet classes by using the java command. Applets are executed in a browser by referencing the applet class in the code= attribute of the <APPLET tag.
    Create an HTML page with the <APPLET tag and your code could execute when you load the html page in a browser if the browser has the java plugin.

  7. #7
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,563
    Rep Power
    25

    Default

    Since JApplet is in the package: javax.swing I assume it is a Swing class

  9. #9
    Mars is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

Similar Threads

  1. Replies: 5
    Last Post: 06-22-2010, 03:51 PM
  2. Execution error: NoSuchMethodError: Main
    By kjharn in forum New To Java
    Replies: 4
    Last Post: 11-02-2009, 08:23 PM
  3. [error] java.lang.NoSuchMethodError: main
    By jon80 in forum New To Java
    Replies: 1
    Last Post: 04-29-2009, 11:21 PM
  4. Replies: 1
    Last Post: 08-07-2007, 07:10 AM
  5. Replies: 1
    Last Post: 08-06-2007, 09:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •