thread main java.lang.NullPointerException Exception in thread main java.lang.NullPointerException

来源:百度知道 编辑:UC知道 时间:2024/05/22 20:26:24
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class Calculator extends Frame implements ActionListener
{
Button buttonCalculate;
TextField wage=null,hours=null,wages=null;
Panel p;
int a,b;
Box baseBox=null,boxV1=null,boxV2=null;
Calculator()
{
wage=new TextField(12);
hours=new TextField(12);
wages=new TextField(12);
buttonCalculate=new Button("Calculate");
buttonCalculate.addActionListener(this);
boxV1=Box.createVerticalBox();
boxV1.add(new Label("Hourly wage"));
boxV1.add(Box.createVerticalStrut(8));
boxV1.add(new Label("Hours worked"));
boxV1.add(Box.createVerticalStrut(8));
boxV1.add(new Label("Gross wages"));
boxV1.add(Box.createVerticalStrut(8));
boxV2=Box.createVerticalBox();
boxV2.add(wage);
boxV2.add(Box.createVer

有例外没有catch,改main方法为:
public static void main(String args[])
{
try{
new Calculator();
}
catch(Exception e){}
}
}

p.s. 上面的程序也有错

你的画板"p"没有new,所以报错了