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

Hi i got the following message error:
"Exception in thread "main" java.lang.NoSuchMethodError: main"

When i compile my file it was successful. Thanks

Here is my code. Maybe somebody can take a look at it.

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

public class Customer extends JApplet
{
//Variable for the panel
static JPanel panelObject;

//variables for labels;
JLabel labelCustName;
JLabel labelCustCellNo;
JLabel labelCustPackage;
JLabel labelCustAge;

//variables for data entry controls
JTextField textCustName;
JTextField textCustCellNo;
JComboBox comboCustPackage;
JTextField textCustAge;

//variables for the layout
GridBagLayout gbObject;
GridBagConstraints gbc;


public void init()
{
//Initialize the layout variables
gbObject = new GridBagLayout();
gbc = new GridBagConstraints();
//panelObject = (JPanel)getContentPane();
//panelObject.setLayout(gbObject);

//Initialize label controls
labelCustName = new JLabel("Customer Name");
labelCustCellNo = new JLabel("Cell Number");
labelCustPackage = new JLabel("Package");
labelCustAge = new JLabel("Age");

//Initialize data entry controls
textCustName = new JTextField(30);
textCustCellNo = new JTextField(15);
textCustAge = new JTextField(2);
String packages[] = {"Executive", "Standard"};
comboCustPackage = new JComboBox(packages);

//Add controls for Customer Name
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 5;
gbObject.setConstraints(labelCustName,gbc);
panelObject.add(labelCustName);

gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 5;
gbObject.setConstraints(textCustName,gbc);
panelObject.add(textCustName);

//Add controls for Cell Number
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 8;
gbObject.setConstraints(labelCustCellNo,gbc);
panelObject.add(labelCustCellNo);

gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 8;
gbObject.setConstraints(textCustCellNo,gbc);
panelObject.add(textCustCellNo);

//Add controls for Package
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 11;
gbObject.setConstraints(labelCustPackage,gbc);
panelObject.add(labelCustPackage);

gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 11;
gbObject.setConstraints(comboCustPackage,gbc);
panelObject.add(comboCustPackage);

//Add controls for Customer Age
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 14;
gbObject.setConstraints(labelCustAge,gbc);
panelObject.add(labelCustAge);

gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 14;
gbObject.setConstraints(textCustAge,gbc);
panelObject.add(textCustAge);

panelObject = (JPanel)getContentPane();
panelObject.setLayout(gbObject);
}
}

Comments

  • : Hi i got the following message error:
    : "Exception in thread "main" java.lang.NoSuchMethodError: main"
    :
    : When i compile my file it was successful. Thanks
    :
    : Here is my code. Maybe somebody can take a look at it.
    :
    : import javax.swing.*;
    : import java.awt.*;
    :
    : public class Customer extends JApplet
    : {
    : //Variable for the panel
    : static JPanel panelObject;
    :
    : //variables for labels;
    : JLabel labelCustName;
    : JLabel labelCustCellNo;
    : JLabel labelCustPackage;
    : JLabel labelCustAge;
    :
    : //variables for data entry controls
    : JTextField textCustName;
    : JTextField textCustCellNo;
    : JComboBox comboCustPackage;
    : JTextField textCustAge;
    :
    : //variables for the layout
    : GridBagLayout gbObject;
    : GridBagConstraints gbc;
    :
    :
    : public void init()
    : {
    : //Initialize the layout variables
    : gbObject = new GridBagLayout();
    : gbc = new GridBagConstraints();
    : //panelObject = (JPanel)getContentPane();
    : //panelObject.setLayout(gbObject);
    :
    : //Initialize label controls
    : labelCustName = new JLabel("Customer Name");
    : labelCustCellNo = new JLabel("Cell Number");
    : labelCustPackage = new JLabel("Package");
    : labelCustAge = new JLabel("Age");
    :
    : //Initialize data entry controls
    : textCustName = new JTextField(30);
    : textCustCellNo = new JTextField(15);
    : textCustAge = new JTextField(2);
    : String packages[] = {"Executive", "Standard"};
    : comboCustPackage = new JComboBox(packages);
    :
    : //Add controls for Customer Name
    : gbc.anchor = GridBagConstraints.NORTHWEST;
    : gbc.gridx = 1;
    : gbc.gridy = 5;
    : gbObject.setConstraints(labelCustName,gbc);
    : panelObject.add(labelCustName);
    :
    : gbc.anchor = GridBagConstraints.NORTHWEST;
    : gbc.gridx = 4;
    : gbc.gridy = 5;
    : gbObject.setConstraints(textCustName,gbc);
    : panelObject.add(textCustName);
    :
    : //Add controls for Cell Number
    : gbc.anchor = GridBagConstraints.NORTHWEST;
    : gbc.gridx = 1;
    : gbc.gridy = 8;
    : gbObject.setConstraints(labelCustCellNo,gbc);
    : panelObject.add(labelCustCellNo);
    :
    : gbc.anchor = GridBagConstraints.NORTHWEST;
    : gbc.gridx = 4;
    : gbc.gridy = 8;
    : gbObject.setConstraints(textCustCellNo,gbc);
    : panelObject.add(textCustCellNo);
    :
    : //Add controls for Package
    : gbc.anchor = GridBagConstraints.NORTHWEST;
    : gbc.gridx = 1;
    : gbc.gridy = 11;
    : gbObject.setConstraints(labelCustPackage,gbc);
    : panelObject.add(labelCustPackage);
    :
    : gbc.anchor = GridBagConstraints.NORTHWEST;
    : gbc.gridx = 4;
    : gbc.gridy = 11;
    : gbObject.setConstraints(comboCustPackage,gbc);
    : panelObject.add(comboCustPackage);
    :
    : //Add controls for Customer Age
    : gbc.anchor = GridBagConstraints.NORTHWEST;
    : gbc.gridx = 1;
    : gbc.gridy = 14;
    : gbObject.setConstraints(labelCustAge,gbc);
    : panelObject.add(labelCustAge);
    :
    : gbc.anchor = GridBagConstraints.NORTHWEST;
    : gbc.gridx = 4;
    : gbc.gridy = 14;
    : gbObject.setConstraints(textCustAge,gbc);
    : panelObject.add(textCustAge);
    :
    : panelObject = (JPanel)getContentPane();
    : panelObject.setLayout(gbObject);
    : }
    : }
    :
    You're trying to run your applet as a application. This is not directly possible. Either run it using the applet viewer or from within a webpage.
    A third option is to add the required main() and display the applet in a JFrame as if it were a JPanel.
  • : : Hi i got the following message error:
    : : "Exception in thread "main" java.lang.NoSuchMethodError: main"
    : :
    : : When i compile my file it was successful. Thanks
    : :
    : : Here is my code. Maybe somebody can take a look at it.
    : :
    : : import javax.swing.*;
    : : import java.awt.*;
    : :
    : : public class Customer extends JApplet
    : : {
    : : //Variable for the panel
    : : static JPanel panelObject;
    : :
    : : //variables for labels;
    : : JLabel labelCustName;
    : : JLabel labelCustCellNo;
    : : JLabel labelCustPackage;
    : : JLabel labelCustAge;
    : :
    : : //variables for data entry controls
    : : JTextField textCustName;
    : : JTextField textCustCellNo;
    : : JComboBox comboCustPackage;
    : : JTextField textCustAge;
    : :
    : : //variables for the layout
    : : GridBagLayout gbObject;
    : : GridBagConstraints gbc;
    : :
    : :
    : : public void init()
    : : {
    : : //Initialize the layout variables
    : : gbObject = new GridBagLayout();
    : : gbc = new GridBagConstraints();
    : : //panelObject = (JPanel)getContentPane();
    : : //panelObject.setLayout(gbObject);
    : :
    : : //Initialize label controls
    : : labelCustName = new JLabel("Customer Name");
    : : labelCustCellNo = new JLabel("Cell Number");
    : : labelCustPackage = new JLabel("Package");
    : : labelCustAge = new JLabel("Age");
    : :
    : : //Initialize data entry controls
    : : textCustName = new JTextField(30);
    : : textCustCellNo = new JTextField(15);
    : : textCustAge = new JTextField(2);
    : : String packages[] = {"Executive", "Standard"};
    : : comboCustPackage = new JComboBox(packages);
    : :
    : : //Add controls for Customer Name
    : : gbc.anchor = GridBagConstraints.NORTHWEST;
    : : gbc.gridx = 1;
    : : gbc.gridy = 5;
    : : gbObject.setConstraints(labelCustName,gbc);
    : : panelObject.add(labelCustName);
    : :
    : : gbc.anchor = GridBagConstraints.NORTHWEST;
    : : gbc.gridx = 4;
    : : gbc.gridy = 5;
    : : gbObject.setConstraints(textCustName,gbc);
    : : panelObject.add(textCustName);
    : :
    : : //Add controls for Cell Number
    : : gbc.anchor = GridBagConstraints.NORTHWEST;
    : : gbc.gridx = 1;
    : : gbc.gridy = 8;
    : : gbObject.setConstraints(labelCustCellNo,gbc);
    : : panelObject.add(labelCustCellNo);
    : :
    : : gbc.anchor = GridBagConstraints.NORTHWEST;
    : : gbc.gridx = 4;
    : : gbc.gridy = 8;
    : : gbObject.setConstraints(textCustCellNo,gbc);
    : : panelObject.add(textCustCellNo);
    : :
    : : //Add controls for Package
    : : gbc.anchor = GridBagConstraints.NORTHWEST;
    : : gbc.gridx = 1;
    : : gbc.gridy = 11;
    : : gbObject.setConstraints(labelCustPackage,gbc);
    : : panelObject.add(labelCustPackage);
    : :
    : : gbc.anchor = GridBagConstraints.NORTHWEST;
    : : gbc.gridx = 4;
    : : gbc.gridy = 11;
    : : gbObject.setConstraints(comboCustPackage,gbc);
    : : panelObject.add(comboCustPackage);
    : :
    : : //Add controls for Customer Age
    : : gbc.anchor = GridBagConstraints.NORTHWEST;
    : : gbc.gridx = 1;
    : : gbc.gridy = 14;
    : : gbObject.setConstraints(labelCustAge,gbc);
    : : panelObject.add(labelCustAge);
    : :
    : : gbc.anchor = GridBagConstraints.NORTHWEST;
    : : gbc.gridx = 4;
    : : gbc.gridy = 14;
    : : gbObject.setConstraints(textCustAge,gbc);
    : : panelObject.add(textCustAge);
    : :
    : : panelObject = (JPanel)getContentPane();
    : : panelObject.setLayout(gbObject);
    : : }
    : : }
    : :
    : You're trying to run your applet as a application. This is not
    : directly possible. Either run it using the applet viewer or from
    : within a webpage.
    : A third option is to add the required main() and display the applet
    : in a JFrame as if it were a JPanel.

    Hi...thank you for replying. Yes i was thinking the same thing about running it using applet viewer it just that i didn't really sure that time. And you confirm it....thanks again..it works now!

    Regards


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories