0

好的,我收到此错误awt eventqueue 0 nullpointerexception error。当我尝试删除一个JPanel.

令我困惑的是,当我删除另一个时JPanel它工作得很好,但这个却没有。下面的第一个代码显示JPanel,当我单击 a 时JButton,它不会删除JPanel.

public class buttontime implements ActionListener { //creating actionlistener for clicking on timebutton to bring up a combobox

    public void actionPerformed(ActionEvent clickTime) {
        Price priceObject = new Price();
        priceObject.getPricepanel();
        remove(priceObject.getPricepanel());
        priceObject.getPricepanel().revalidate();

        add(timeObject.getTimePanel(), BorderLayout.EAST);
        timeObject.getTimePanel().revalidate();


    }
}

//This one gives me 0 errors.
public class buttonprice implements ActionListener { //creating actionlistener for clicking on timebutton to bring up a combobox

    public void actionPerformed(ActionEvent ClickPrice) {


        Price priceObject = new Price();
        priceObject.SelectPrice();
        remove(timeObject.getTimePanel());
        timeObject.getTimePanel().revalidate();

        add(priceObject.getPricepanel(), BorderLayout.EAST);
        priceObject.getPricepanel().revalidate();


    }
}
4

1 回答 1

1
remove(priceObject.getPricepanel());

NullPointerException如果您仅在移除此面板时得到一个,则priceObject.getPricepanel()必须返回null

于 2013-03-20T23:36:29.947 回答