Eclipse suggests Null Pointer exception, though I believe I initialized my object

后端 未结 3 1930
臣服心动
臣服心动 2020-12-22 03:14

As the title says I have NPE error. It happens on line:

while (getWidth() > bowl.getX()+10) {

If I remove it, it shows it happens on nex

3条回答
  •  爱一瞬间的悲伤
    2020-12-22 04:03

    You are shadowing your bowl field at the class level in the init method,

    private GOval bowl; 
    
    public void init() {
      // GOval bowl = new GOval(10,10);
      bowl = new GOval(10,10);
      add(bowl);
      addMouseListeners();
    }
    

提交回复
热议问题