Java 发生致命异常

Java 发生致命异常,java,Java,我有一个相当大的项目,我在这里工作,我正在调整一个部分,现在我得到了这个错误框,当我尝试运行代码时弹出。这是工作之前,唯一的是我改变了是“创建承包商”。我认为错误要么在那个部分,要么一直在底部。我正在使用Eclipse来运行代码,在运行代码之后,我不仅会弹出该框,还会在代码底部显示一条消息,上面写着:java.lang.NoSuchMethodError:main Exception in thread“main” import java.awt.*; 导入javax.swing.*; 导入ja

我有一个相当大的项目,我在这里工作,我正在调整一个部分,现在我得到了这个错误框,当我尝试运行代码时弹出。这是工作之前,唯一的是我改变了是“创建承包商”。我认为错误要么在那个部分,要么一直在底部。我正在使用Eclipse来运行代码,在运行代码之后,我不仅会弹出该框,还会在代码底部显示一条消息,上面写着:java.lang.NoSuchMethodError:main Exception in thread“main”

import java.awt.*;
导入javax.swing.*;
导入java.awt.event.*;
导入java.io.*;
公共类测试扩展JFrame实现ActionListener{
私人JTabbedPane JTabbedPane;
私人杰帕内尔将军;
私人JPanel池;
私人JPanel浴缸;
私人JPanel客户;
私人JPanel承包商;
JTextField lengthTextPool、widthTextPool、depthTextPool、volumeTextPool、,
长度文本浴缸、宽度文本浴缸、深度文本浴缸、体积文本浴缸;
JTextArea名称textCustomers、ExistTextCustomers;
公开考试(){
setTitle(“体积计算器”);
设置大小(300200);
JPanel-topPanel=新的JPanel();
setLayout(新的BorderLayout());
getContentPane().add(topPanel);
createGeneral();
createPools();
createHotTub();
createCustomers();
创建承包商();
jtabbedPane=新的jtabbedPane();
jtabbedPane.addTab(“一般”,一般);
jtabbedPane.addTab(“池”,池);
jtabbedPane.addTab(“热浴缸”,热浴缸);
jtabbedPane.addTab(“客户”,客户);
jtabbedPane.addTab(“承包商”,承包商);
添加(jtabbedPane,BorderLayout.CENTER);
}
/*一般的*/
公共资源(通用){
通用=新JPanel();
General.setLayout(空);
JLabel DateLabel=新的JLabel(“今天的日期”);
日期标签.立根(10,15,150,20);
一般。添加(日期标签);
JFormattedTextField日期=新建JFormattedTextField(
java.util.Calendar.getInstance().getTime());
date.setEditable(false);
日期:挫折(90,15150,20);
总则.添加(日期);
JButton Exit=新JButton(“Exit”);
出口.后退(20,50,80,20);
Exit.addActionListener(this);
出口。后退地面(颜色。白色);
一般。添加(退出);
}
/*创建池*/
公共void createPools(){
Pools=newjpanel();
Pools.setLayout(null);
JLabel lengthLabelPool=新JLabel(“池的长度(英尺):”;
长度标签工具立根(10,15,260,20);
池。添加(lengthLabelPool);
lengthTextPool=新的JTextField();
lengthTextPool.setBounds(180,15,150,20);
添加(lengthTextPool);
JLabel widthLabelPool=新JLabel(“池的宽度(英尺):”;
立根宽度(10,40,260,20);
池。添加(widthLabelPool);
widthTextPool=新的JTextField();
宽度TEXTPOOL.setBounds(180,40,150,20);
pool.add(widthTextPool);
JLabel depthLabelPool=新JLabel(“池的平均深度(英尺):”;
深潜潜工具立根(10,65,260,20);
添加(depthLabelPool);
depthTextPool=新的JTextField();
深度TEXTPOOL.setBounds(180,65,150,20);
Pools.add(depthTextPool);
JLabel volumeLabelPool=新JLabel(“池的体积为:(ft^3”);
卷轴(10110260,20);
池。添加(volumeLabelPool);
volumeTextPool=新的JTextField();
volumeTextPool.setBounds(180、110、150、20);
volumeTextPool.setEditable(false);
Pools.add(volumeTextPool);
JButton calcVolumePool=新JButton(“计算池容积”);
calcVolumePool.立根(20250180,20);
calcVolumePool.addActionListener(此);
calcVolumePool.setBackground(颜色:白色);
Pools.add(calcVolumePool);
JButton Exit=新JButton(“Exit”);
出口.立根(220250,80,20);
Exit.addActionListener(this);
出口。后退地面(颜色。白色);
添加(退出);
}
/*创建热浴缸*/
公共浴盆(){
HotTub=新的JPanel();
HotTub.setLayout(空);
JLabel lengthLabel2=新JLabel(“热水槽长度(英尺):”;
长度标签2.立根(10,15,260,20);
热浴缸。添加(长度标签2);
lengthTextHotTub=新的JTextField();
lengthTextHotTub.立根(180,15,150,20);
添加(lengthTextHotTub);
JLabel widthLabelHotTub=新JLabel(“热水槽宽度(英尺):”;
立根宽度(10,40,260,20);
热浴缸。添加(宽度标签热浴缸);
widthTextHotTub=新的JTextField();
宽度(180,40,150,20);
HotTub.添加(宽度文本HotTub);
JLabel depthLabelHotTub=新JLabel(“热水浴缸的平均深度(英尺):”;
深渊(10,65,260,20);
热浴盆。添加(depthLabelHotTub);
depthTextHotTub=新的JTextField();
深度文本热浴缸立根(180,65,150,20);
HotTub.add(depthTextHotTub);
JLabel volumeLabelHotTub=新JLabel(“热水浴缸的体积为:(英尺^3”);
卷轴(10,110,260,20);
热浴盆。添加(卷带热浴盆);
volumeTextHotTub=新的JTextField();
体积外浴缸.立根(180,110,150,20);
volumeTextHotTub.setEditable(false);
添加(volumeTextHotTub);
JButton calcVolume=新JButton(“计算热水浴缸容积”);
立根体积(20250180,20);
calcVolume.addActionListener(this);
立根体积(颜色:白色);
热浴缸。添加(calcVolume);
JButton Exit=新JButton(“Exit”);
出口.立根(220250,80,20);
Exit.addActionListener(this);
出口。后退地面(颜色。白色);
热水器。添加(退出);
}
/*创造客户*/
公众客户(){
客户=新JPanel();
Customers.setLayout(空);
NameTextCustomers=新的JTextArea();
NameTextCustomers.setBounds(10,10350,150);
NameTextCustomers.setLineWrap(true);
Customers.add(NameTextCustomers);
JButton Exit=新JButton(“Exit”);
出口.立根(30170,80,20);
Exit.addActionLi
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;

public class test extends JFrame implements ActionListener{
private JTabbedPane jtabbedPane;
private JPanel General;
private JPanel Pools;
private JPanel HotTub;
private JPanel Customers;
private JPanel Contractors;

JTextField lengthTextPool, widthTextPool, depthTextPool, volumeTextPool,
lengthTextHotTub, widthTextHotTub, depthTextHotTub, volumeTextHotTub;

JTextArea NameTextCustomers, ExistTextCustomers;


public test(){
setTitle("Volume Calculator");
setSize(300, 200);

JPanel topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );

createGeneral();
createPools();
createHotTub();
createCustomers();
createContractors();

jtabbedPane = new JTabbedPane();
jtabbedPane.addTab("General", General);
jtabbedPane.addTab("Pool", Pools);
jtabbedPane.addTab("Hot Tub", HotTub);
jtabbedPane.addTab("Customers", Customers);
jtabbedPane.addTab("Contractors", Contractors);
topPanel.add(jtabbedPane, BorderLayout.CENTER);
              }

/*        GENERAL        */

public void createGeneral(){
    General = new JPanel();
    General.setLayout( null );

    JLabel DateLabel = new JLabel("Today's Date");
    DateLabel.setBounds(10, 15, 150, 20);
    General.add( DateLabel );
    JFormattedTextField date = new JFormattedTextField(
            java.util.Calendar.getInstance().getTime());
            date.setEditable(false);
            date.setBounds(90,15,150,20);
            General.add(date);

            JButton Exit = new JButton("Exit");
            Exit.setBounds(20,50,80,20);
            Exit.addActionListener(this);
            Exit.setBackground(Color.white);
            General.add(Exit);
                                     }
/*        CREATE POOL        */

public void createPools(){
    Pools = new JPanel();
    Pools.setLayout( null );
JLabel lengthLabelPool = new JLabel("Length of pool (ft):");
    lengthLabelPool.setBounds(10, 15, 260, 20);
    Pools.add( lengthLabelPool );
lengthTextPool = new JTextField();
    lengthTextPool.setBounds(180, 15, 150, 20);
    Pools.add( lengthTextPool );
JLabel widthLabelPool = new JLabel("Width of pool (ft):");
    widthLabelPool.setBounds(10, 40, 260, 20);
    Pools.add( widthLabelPool );
widthTextPool = new JTextField();
    widthTextPool.setBounds(180, 40, 150, 20);
    Pools.add( widthTextPool );
JLabel depthLabelPool = new JLabel("Average Depth of pool (ft):");
    depthLabelPool.setBounds( 10, 65, 260, 20 );
    Pools.add( depthLabelPool );
depthTextPool = new JTextField();
    depthTextPool.setBounds(180, 65, 150, 20);
    Pools.add( depthTextPool );
JLabel volumeLabelPool = new JLabel("The pool's volume is:(ft ^3");
    volumeLabelPool.setBounds(10, 110, 260, 20);
    Pools.add( volumeLabelPool );
    volumeTextPool = new JTextField();
    volumeTextPool.setBounds(180, 110, 150, 20);
    volumeTextPool.setEditable(false);
Pools.add(volumeTextPool);

JButton calcVolumePool = new JButton("Calculate Pool Volume");
    calcVolumePool.setBounds(20,250,180,20);
    calcVolumePool.addActionListener(this);
    calcVolumePool.setBackground(Color.white);
    Pools.add(calcVolumePool);

JButton Exit = new JButton("Exit");
    Exit.setBounds(220,250,80,20);
    Exit.addActionListener(this);
    Exit.setBackground(Color.white);
    Pools.add(Exit);
                       }

/*        CREATE HOT TUB        */

public void createHotTub(){
    HotTub = new JPanel();
    HotTub.setLayout( null );
JLabel lengthLabel2 = new JLabel("Length of Hot Tub (ft):");
    lengthLabel2.setBounds(10, 15, 260, 20);
    HotTub.add( lengthLabel2 );
lengthTextHotTub = new JTextField();
    lengthTextHotTub.setBounds(180, 15, 150, 20);
    HotTub.add( lengthTextHotTub );
JLabel widthLabelHotTub = new JLabel("Width of Hot Tub (ft):");
    widthLabelHotTub.setBounds(10, 40, 260, 20);
    HotTub.add( widthLabelHotTub );
widthTextHotTub = new JTextField();
    widthTextHotTub.setBounds(180, 40, 150, 20);
    HotTub.add( widthTextHotTub );
JLabel depthLabelHotTub = new JLabel("Average Depth of Hot Tub (ft):");
    depthLabelHotTub.setBounds( 10, 65, 260, 20 );
    HotTub.add( depthLabelHotTub );
depthTextHotTub = new JTextField();
    depthTextHotTub.setBounds(180, 65, 150, 20);
    HotTub.add( depthTextHotTub );
JLabel volumeLabelHotTub = new JLabel("The Hot Tub's volume is:(ft ^3");
    volumeLabelHotTub.setBounds(10, 110, 260, 20);
    HotTub.add( volumeLabelHotTub );
    volumeTextHotTub = new JTextField();
    volumeTextHotTub.setBounds(180, 110, 150, 20);
    volumeTextHotTub.setEditable(false);
    HotTub.add(volumeTextHotTub);

JButton calcVolume = new JButton("Calculate Hot Tub Volume");
    calcVolume.setBounds(20,250,180,20);
    calcVolume.addActionListener(this);
    calcVolume.setBackground(Color.white);
    HotTub.add(calcVolume);

JButton Exit = new JButton("Exit");
    Exit.setBounds(220,250,80,20);
    Exit.addActionListener(this);
    Exit.setBackground(Color.white);
    HotTub.add(Exit);
                       }
/*        CREATE CUSTOMERS        */

public void createCustomers(){
    Customers = new JPanel();
    Customers.setLayout( null );

    NameTextCustomers = new JTextArea();
    NameTextCustomers.setBounds(10, 10, 350, 150);
    NameTextCustomers.setLineWrap(true);
    Customers.add(NameTextCustomers);

    JButton Exit = new JButton("Exit");
    Exit.setBounds(30,170,80,20);
    Exit.addActionListener(this);
    Exit.setBackground(Color.white);
    Customers.add(Exit);

    JButton AddCustomers = new JButton("Add Customer");
    AddCustomers.setBounds(130,170,120,20);
    AddCustomers.setBackground(Color.white);
    Customers.add(AddCustomers);

    JButton Refresh = new JButton("Refresh");
    Refresh.setBounds(260,170,80,20);
    Refresh.setBackground(Color.white);
    Customers.add(Refresh);

    ExistTextCustomers = new JTextArea();
    ExistTextCustomers.setBounds(10, 200, 350, 60);
    ExistTextCustomers.setLineWrap(true);
    Customers.add(ExistTextCustomers);

}
/*        CREATE CONTRACTORS        */

public JPanel createContractors(){ 
    final JTextArea contArea = new JTextArea(6, 30); 
    final JTextArea contMessage; 
    JButton addContractor = new JButton("Add Contractor"); 

    addContractor.setMnemonic('a'); 

JPanel contPanel = new JPanel(); 
contArea.setText("Select Add Contractor to add contractor. Select Refresh to refresh this pane."); 
contArea.setForeground(Color.orange); 
contArea.setLineWrap(true); 
contArea.setWrapStyleWord(true); 
JButton contRefButton = new JButton("Refresh"); 
contMessage = new JTextArea(2, 30); 
contMessage.setLineWrap(true); 
contMessage.setWrapStyleWord(true); 

addContractor.addActionListener(new ActionListener() 
{ 
public void actionPerformed(ActionEvent e) 
{ // action if button is used 
new Contractor("Contractor"); 
}// end actionPerformed()//end action performed 
}); // end performed action 

contPanel.add(contArea); 
contPanel.add(addContractor); 
contPanel.add(contRefButton); 
contPanel.add(contMessage); 
contRefButton.setMnemonic('R'); 

contRefButton.addActionListener(new ActionListener() 
{ 
public void actionPerformed(ActionEvent e) 
{ 
contMessage.setText(""); 
try
{ 
File contOpen = new File("contractor.txt"); 
FileReader contAreaIn = new FileReader(contOpen); 
contArea.read(contAreaIn, contOpen.toString()); 
contMessage.setText("The file exists and can be read from."); 
} 
catch (IOException e3) 
{ 
contMessage.setText("The file can't be read." + e3.getMessage()); 
} 
} 
}); 

return contPanel; 
} 

class Contractor extends JFrame 
{ 
private String[] states = { "AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", 
"FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", 
"MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", 
"NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", 
"TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY" }; 
private JComboBox StateList = new JComboBox(states); 
private JTextField NameText = new JTextField(25); 
private JTextField AddressText = new JTextField(25); 
private JTextField CityText = new JTextField(25); 
private JTextField ZipText = new JTextField(9); 
private JTextField PhoneText = new JTextField(10); 
private JTextField PopMessageText = new JTextField(30); 
private static final long serialVersionUID = 1L; 

private AddContButtonHandler addContHandler = new AddContButtonHandler(); 

public Contractor(String who) 
{ 
popUpWindow(who); 
} 

public void popUpWindow(final String who) { 

final JFrame popWindow; 
popWindow = new JFrame(who); 
popWindow.setSize(425, 350); 
popWindow.setLocation(100, 100); 
popWindow.setVisible(true); 
setDefaultCloseOperation(EXIT_ON_CLOSE); 

Container A = new Container(); 

popWindow.add(A); 

A.setLayout(new FlowLayout()); 

JPanel Name = new JPanel(); 
JPanel Address = new JPanel(); 
JPanel City = new JPanel(); 
JPanel SZP = new JPanel(); 
JPanel File = new JPanel(); 
JPanel Message = new JPanel(); 

Name.add(new JLabel(who + "Name")); 
Name.add(NameText); 
Address.add(new JLabel("Address")); 
Address.add(AddressText); 
City.add(new JLabel("City")); 
City.add(CityText); 
SZP.add(new JLabel("State")); 
StateList.setSelectedIndex(0); 
SZP.add(StateList); 
SZP.add(new JLabel("Zip")); 
SZP.add(ZipText); 
SZP.add(new JLabel("Phone")); 
SZP.add(PhoneText); 
JButton addwho = new JButton("Add" + who); 
addwho.setMnemonic('A'); 
JButton close = new JButton("Close"); 
close.setMnemonic('C'); 
JButton deleteFile = new JButton("Delete File"); 
deleteFile.setMnemonic('D'); 
File.add(addwho); 
File.add(close); 
File.add(deleteFile); 
        PopMessageText.setEditable(false); 
        PopMessageText.setHorizontalAlignment(JTextField.CENTER); 

Message.add(PopMessageText); 
    A.add(Name); 
    A.add(Address); 
    A.add(City); 
    A.add(SZP); 
    A.add(File); 
    A.add(Message); 

deleteFile.setToolTipText("Delete File"); 
addwho.setToolTipText("Add "+ who); 
close.setToolTipText("Close"); 

if (who == "Contractor") 
    addwho.addActionListener(addContHandler); // registers listener 

close.addActionListener(new ActionListener() { 
public void actionPerformed(ActionEvent e) { 
    NameText.setText(""); 
    AddressText.setText(""); 
    CityText.setText(""); 
    ZipText.setText(""); 
    PhoneText.setText(""); 
    PopMessageText.setText(""); 
    popWindow.dispose(); 
                                          } 
                   }); 

deleteFile.addActionListener(new ActionListener() { 
public void actionPerformed(ActionEvent e) { 
PopMessageText.setText(""); 
if (who == "Contractor") { 
    File file = new File("Contractor.txt"); 
boolean contFileDeleted = file.delete(); 
if (contFileDeleted) { 
    PopMessageText 
    .setText("Contractor file deleted"); 
               } else { 
                       PopMessageText 
                       .setText("Error deleting file"); 
        } 
                         } 
                                        } 
                         }); 
}

class AddContButtonHandler implements ActionListener { 
public void actionPerformed(ActionEvent addContHandler) { 
int StateIndex; 
try { 
File file = new File("Contractor.txt"); 

boolean success = file.createNewFile(); 

if (success) { 
   PopMessageText 
    .setText("Contractor.txt file created file added"); 
                            } else if (file.canWrite()) { 
    PopMessageText 
    .setText("Writing info. to Contractor.txt, file added"); 
                            } else { 
                              PopMessageText.setText("Cannot create file: Contractor.txt"); 
       } 
try { 
FileWriter fileW = new FileWriter("Contractor.txt", true); 
fileW.write(NameText.getText()); 
fileW.write(","); 
fileW.write(AddressText.getText()); 
fileW.write(","); 
fileW.write(CityText.getText()); 
fileW.write(","); 
StateIndex = StateList.getSelectedIndex(); 
fileW.write(states[StateIndex]); 
fileW.write(","); 
fileW.write(ZipText.getText()); 
fileW.write(","); 
fileW.write(PhoneText.getText()); 
fileW.write("\r\n"); 
fileW.close(); 
PopMessageText.setText("Contractor has been added!"); 

FileReader fileR = new FileReader("Contractor.txt"); 
BufferedReader buffIn = new BufferedReader(fileR); 

buffIn.readLine(); 
buffIn.close(); 
   }

catch (IOException e1) { 
JOptionPane.showMessageDialog(null, e1.getMessage(), 
"Error", 2);
                       }
    NameText.setText(""); 
    AddressText.setText(""); 
    CityText.setText(""); 
    ZipText.setText(""); 
    PhoneText.setText(""); 
} catch (IOException e1) { 
                         }

}
}


public void actionPerformed(ActionEvent event){
JButton button = (JButton)event.getSource();
String buttonLabel = button.getText();
if ("Exit".equalsIgnoreCase(buttonLabel)){
Exit_pressed(); return;
    }
    if ("Calculate Pool Volume".equalsIgnoreCase(buttonLabel)){
        Calculate_VolumePool(); return;
    }
        if ("Calculate Hot Tub Volume".equalsIgnoreCase(buttonLabel)){
            Calculate_VolumeHotTub(); return;
    }
                                             }
private void Exit_pressed(){
System.exit(0);
                           }
private void Calculate_VolumePool(){
String lengthStringPool, widthStringPool, depthStringPool;
    int lengthPool=0;
    int widthPool=0;
    int depthPool=0;
lengthStringPool = lengthTextPool.getText();
widthStringPool = widthTextPool.getText();
depthStringPool = depthTextPool.getText();
if (lengthStringPool.length() < 1 || widthStringPool.length() < 1 || depthStringPool.length() < 1 ){
    volumeTextPool.setText("Enter All 3 Numbers"); return;
    }
        lengthPool = Integer.parseInt(lengthStringPool);
        widthPool = Integer.parseInt(widthStringPool);
        depthPool = Integer.parseInt(depthStringPool);
            if (lengthPool != 0 || widthPool != 0 || depthPool != 0 ){
                volumeTextPool.setText((lengthPool * widthPool * depthPool) + "");
    } else{
        volumeTextPool.setText("Enter All 3 Numbers"); return;
      }
                               }

private void Calculate_VolumeHotTub(){
    String lengthStringHotTub, widthStringHotTub, depthStringHotTub;
        int lengthHotTub=0;
        int widthHotTub=0;
        int depthHotTub=0;
    lengthStringHotTub = lengthTextHotTub.getText();
    widthStringHotTub = widthTextHotTub.getText();
    depthStringHotTub = depthTextHotTub.getText();
    if (lengthStringHotTub.length() < 1 || widthStringHotTub.length() < 1 || depthStringHotTub.length() < 1 ){
        volumeTextHotTub.setText("Enter All 3 Numbers"); return;
        }
            lengthHotTub = Integer.parseInt(lengthStringHotTub);
            widthHotTub = Integer.parseInt(widthStringHotTub);
            depthHotTub = Integer.parseInt(depthStringHotTub);
                if (lengthHotTub != 0 || widthHotTub != 0 || depthHotTub != 0 ){
                    volumeTextHotTub.setText((lengthHotTub * widthHotTub * depthHotTub) + "");
        } else{
            volumeTextHotTub.setText("Enter All 3 Numbers"); return;
          }
                                   }
public void main(String[] args){
JFrame frame = new test();
frame.setSize(380, 350);
frame.setVisible(true);
}
}
public void actionPerformed(ActionEvent e) {

}
}
public void main(String[] args){
public void main(String[] args) // bad
public static void main(String[] args) // good