0

OK、このエラーが発生しています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();


    }
}
4

1 に答える 1

1
remove(priceObject.getPricepanel());

NullPointerExceptionこのパネルを取り外したときにのみを取得している場合は、 をpriceObject.getPricepanel()返す必要がありますnull

于 2013-03-20T23:36:29.947 に答える