DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2005
    Posts
    1

    Why its giving this msg " Exception in thread "main" java.lang.NoSuchMethodError: mai

    // Java packages
    import java.awt.Graphics; // import class Graphics
    import javax.swing.JApplet; // import class JApplet

    public class WelcomeApplet2 extends JApplet {

    // draw text on applet’s background
    public void paint( Graphics g )
    {
    // call superclass version of method paint
    super.paint( g );

    // draw two Strings at different locations
    g.drawString( "Welcome to", 25, 25 );
    g.drawString( "Java Programming!", 25, 40 );

    } // end method paint

    } // end class WelcomeApplet2





    /* when i compfile javac WelcomeApplet2.java its fine it make the class file then run the class file
    java WelcomeApplet2
    it gives this message
    Exception in thread "main" java.lang.NoSuchMethodError: main

    */

  2. #2
    Join Date
    Dec 2003
    Location
    tx/us
    Posts
    131
    You're trying to run it like an application, which has to have a main() method. Applets you run with the applet runner or put them in a web page and run them in a browser.

  3. #3
    Join Date
    Dec 2008
    Posts
    2

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

    Hi

    I'm getting this error as well when I compile this program with when I try to run this program.

    F:\jdk6\bin>javac Motocycle.java

    F:\jdk6\bin>java Motocycle
    Exception in thread "main" java.lang.NoSuchMethodError: main




    class Motorcycle
    {
    String make;
    String color;
    boolean enginstate;


    public static void main (String args[])
    {
    Motorcycle m = new Motorcycle();
    m.make = "Yamaha RZ350";
    m.color = "Yellow";
    System.out.println("calling showAtts...");
    m.showAtts();

    System.out.println("--------");
    System.out.println("Starting engine....");
    m.startEngine();

    System.out.println("--------");
    System.out.println("Starting showAtts....");
    m.showAtts();

    System.out.println("--------");
    System.out.println("Starting engine....");
    m.startEngine();
    }

    void startEngine()
    {
    if (enginstate == true)
    System.out.println("The engine is aready on.");
    else
    {
    enginstate = true;
    System.out.println("The engine is now on.");
    }
    }

    void showAtts()
    {
    System.out.println("This motocycle is a " + color + " " + make);

    if ( enginstate = true)
    System.out.println("The engine is off ");
    else
    System.out.println("The engine is on " );
    }



    }

  4. #4
    Join Date
    Dec 2008
    Posts
    2

    Smile Found the error -da. Fat Fingers



    Saw it right after my submission:

    F:\jdk6\bin>javac Motocycle.java

    F:\jdk6\bin>java Motocycle
    Exception in thread "main" java.lang.NoSuchMethodError: main


    Forgot the r in Motocycle / F:\jdk6\bin>javac Motorcycle.java

    F:\jdk6\bin>java Motorcycle

    The program ran fine

    Bye

  5. #5
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,652
    Welcome to DevX and thanks for posting your solution.

    Hopefully it will help others.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links