Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: program in java

  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    program in java

    i have the following code:
    Code:
    //: Button1.java
    // Putting buttons on an applet
    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 exute it the following error appear:
    exception in thred main java.lang.nosuchmethoderror: main
    why?

  • #2
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    don't you need the

    public class void main(String args[])

    class to run an applet? And an init() method?

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how can i do it?

  • #4
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you should be able to add a
    public void main( ) {
    ...
    ...
    }
    just before the last bracket so that it is still apart of the class Applet you are using but you already have an init( ) and the main goes below that cause that is the first thing that java will look at.

    Jason


  •  

    Posting Permissions

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