【问题标题】:awt eventqueue 0 nullpointerexception errorawt 事件队列 0 空指针异常错误
【发布时间】:2013-03-20 23:34:02
【问题描述】:

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

让我感到困惑的是,当我删除另一个 JPanel 时,它工作得非常好,但这个却没有。下面的第一个代码显示了JPanel,当我单击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();


    }
}

【问题讨论】:

    标签: java swing user-interface nullpointerexception actionlistener


    【解决方案1】:
    remove(priceObject.getPricepanel());
    

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

    【讨论】:

    • 当我添加 priceObject.getPricepanel() 时它如何工作,但是当我删除它时,我得到了那个错误我该如何克服这个错误完全让我感到困惑
    • @user2188332 可能在你添加它之后因为 null
    • 听起来更像timeObject 为空
    • @MadProgrammer 但他说timeObject 的那个正在工作
    • 我可以把我的代码发给别人吗,因为我真的很困惑试图解决这个问题一个小时
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-15
    • 2013-03-22
    • 2020-04-29
    • 2017-10-28
    相关资源
    最近更新 更多