gpt4 book ai didi

java - awt eventqueue 0 空指针异常错误

转载 作者:行者123 更新时间:2023-12-01 14:44:51 26 4
gpt4 key购买 nike

好的,我收到此错误 awt eventqueue 0 nullpointerexception 错误。当我尝试删除 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();


}
}

最佳答案

remove(priceObject.getPricepanel());

如果仅在删除此面板时出现 NullPointerException,则 priceObject.getPricepanel() 必须返回 null

关于java - awt eventqueue 0 空指针异常错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15536790/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com