awt eventqueue 0 nullpointerexception error

China☆狼群 提交于 2019-12-20 07:15:23

问题


Ok I'm getting this error awt eventqueue 0 nullpointerexception error. When I try to remove a JPanel.

Whats confusing me is when I remove another JPanel it works perfectly fine but this one it doesn't. The first Code below shows the JPanel that when I click on a JButton it doesn't remove the 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();


    }
}

回答1:


remove(priceObject.getPricepanel());

If you are getting a NullPointerException only when removing this panel, priceObject.getPricepanel() must be returning null.



来源:https://stackoverflow.com/questions/15536790/awt-eventqueue-0-nullpointerexception-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!