问题
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