Topic: 求助:java.lang.NullPointerException问题

  Print this page

1.求助:java.lang.NullPointerException问题 Copy to clipboard
Posted by: cxc3980
Posted on: 2006-05-11 19:35

程序如下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.util.LinkedList;
import java.text.NumberFormat;
public class Calculate extends JFrame implements ActionListener {
NumberButton numberButton[];
OperationButton operationButton[];
JButton dotButton,deButton,signButton,recButton,equalsignButton,resetButton;
JPanel panel;
JTextField resultShow;
JLabel label;
String operation[]={"+","-","*","/"};
LinkedList linkedList;
boolean PequalsignButton=false;

/** Creates a new instance of Calculate */
public Calculate() {
linkedList=new LinkedList();
numberButton=new NumberButton[10];
for(int i=0;i<=9;i++){
numberButton[i]=new NumberButtonLight Bulb;
numberButton[i].addActionListener(this);
}
operationButton=new OperationButton[4];
for(int i=0;i<3;i++){
operationButton[i]=new OperationButton(operation[i]);
operationButton[i].addActionListener(this);
}
dotButton=new JButton(".");
deButton=new JButton("de");
signButton=new JButton("+/-");
recButton=new JButton("1/x");
equalsignButton=new JButton("=");
resetButton=new JButton("reset");
dotButton.setForeground(Color.blue);
deButton.setForeground(Color.blue);
signButton.setForeground(Color.blue);
recButton.setForeground(Color.blue);
equalsignButton.setForeground(Color.blue);
resetButton.setForeground(Color.blue);
dotButton.addActionListener(this);
deButton.addActionListener(this);
signButton.addActionListener(this);
recButton.addActionListener(this);
equalsignButton.addActionListener(this);
resetButton.addActionListener(this);
resultShow=new JTextField(10);
resultShow.setHorizontalAlignment(JTextField.RIGHT);
resultShow.setForeground(Color.blue);
resultShow.setFont(new Font("TimesRoman",Font.PLAIN,14));
resultShow.setBorder(new SoftBevelBorder(BevelBorder.LOWERED));
resultShow.setBackground(Color.white);
resultShow.setEditable(false);

panel=new JPanel();
panel.setLayout(new GridLayout(4,5));

panel.add(numberButton[1]);
panel.add(numberButton[2]);
panel.add(numberButton[3]);
panel.add(operationButton[0]);
panel.add(resetButton);

panel.add(numberButton[4]);
panel.add(numberButton[5]);
panel.add(numberButton[6]);
panel.add(operationButton[1]);
panel.add(deButton);

panel.add(numberButton[7]);
panel.add(numberButton[8]);
panel.add(numberButton[9]);
panel.add(operationButton[2]);
panel.add(recButton);

panel.add(numberButton[0]);
panel.add(signButton);
panel.add(dotButton);
panel.add(operationButton[3]);
panel.add(equalsignButton);

add(panel,BorderLayout.CENTER);
add(resultShow,BorderLayout.NORTH);

addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
setVisible(true);
setBounds(100,50,240,180);
setResizable(false);
validate();
}

public void actionPerformed(ActionEvent actionEvent) {
}
public static void main(String args[]){
new Calculate();
}
}
运行后提示如下的错误:
java.lang.NullPointerException

at java.awt.Container.addImpl(Container.java:625)

at java.awt.Container.add(Container.java:307)

at Calculate.<init>(Calculate.java:96)

at Calculate.main(Calculate.java:117)

Exception in thread "main"

Java Result: 1
请问是什么原因阿?

2.Re:求助:java.lang.NullPointerException问题 [Re: cxc3980] Copy to clipboard
Posted by: liuzhenke15
Posted on: 2006-05-12 13:43

你的NumberButton从何来
该问题只要跟踪一下Calculate.java的第96行应该很容易解决的,你提供的程序不全,没法帮你Debug


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923