Results 1 to 2 of 2
  1. #1
    fernando is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default exception in thred main java.lang.nosuchmethoderror: main

    Hi, I have the following code:

    Java Code:
    import java.awt.*;
    import java.applet.*;
    public class Button1 extends Applet {
    Button
    b1 = new Button("Button 1"),
    b2 = new Button("Button 2");
    public void init() {
    add(b1);
    add(b2);
    }
    }
    When i compile it, everything going alright, but when i execute it the following error appear:
    exception in thread main java.lang.nosuchmethoderror: main
    why?
    Thanks.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    At the prompt you run an application with >java MyClass.java
    For an applet you use the appletviewer: >appletviewer MyApplet.java
    and for this to work your java/source file must have an applet tag in it, like so
    Java Code:
    //  <applet code="Button1" width="200" height="200"></applet>
    java.awt.*;
    import java.applet.*;
    
    public class Button1 extends Applet {
        Button
            b1 = new Button("Button 1"),
            b2 = new Button("Button 2");
    
        public void init() {
            add(b1);
            add(b2);
        }
    }

Similar Threads

  1. Replies: 8
    Last Post: 03-05-2011, 03:53 AM
  2. Replies: 1
    Last Post: 08-07-2007, 07:10 AM
  3. Replies: 1
    Last Post: 07-31-2007, 01:54 PM
  4. Replies: 1
    Last Post: 07-25-2007, 10:55 PM
  5. Replies: 1
    Last Post: 07-16-2007, 06:32 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
  •