• 1 reply
  • Latest Post - ‏2004-06-30T12:06:34Z by SystemAdmin
4672 Posts

Pinned topic java.lang.NoSuchMethodError: main

‏2004-06-26T14:52:27Z |
What is wrong with my program?
I have done everything I can do please help me.

package add;

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class add extends Applet implements ActionListener
TextField num1 = new TextField( 1000 ); // some objects for the window
TextField num2 = new TextField( 1000 );
Label theAnswer = new Label("0000");
Button addButton = new Button("add");
private JTextArea jTextArea1 = new JTextArea();
public void init()
add( num1 ); // add the objects to the window
add( num2);
add( addButton );
add( theAnswer );

public void actionPerformed(ActionEvent thisEvent)
int first = Integer.parseInt( num1.getText( ) );
int second = Integer.parseInt( num2.getText( ) );
int total = first + second;

theAnswer.setText( " = " + total );
Updated on 2004-06-30T12:06:34Z at 2004-06-30T12:06:34Z by SystemAdmin
  • SystemAdmin
    4672 Posts

    Re: java.lang.NoSuchMethodError: main

    You probably want to execute the file from command line like "java Add", but this does not work as you really don't have the "main" method defined.

    Use the following way to test your applet (I have tried it with your source and it works):

    1) Make an HTML file (Add.html) including the following line of code: <APPLET CODE="Add.class" WIDTH="100" HEIGHT="100"> </APPLET>

    2) Go to the console window and locate your files. Then type: appletviewer Add.html :)