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


as title says have npe error. happens on line:

while (getwidth() > bowl.getx()+10) { 

if remove it, shows happens on next line:

bowl.move(10.0, 0); 

i concluded eclipse not see "bowl" initialized. why? doesn't "new goval" deal that? i've seen in 1 of threads here solution split declaration , initialization different lines, think unlikely primary solution (besides, didn't in case) suggestions on code?

this code supposed create circle, put in left-upper corner of screen, , move circle after mouse-button clicked. circle drawn successfully, npe message shows after click.

import acm.program.*; import acm.graphics.*; import java.awt.event.*;  public class animation extends graphicsprogram {  public void init() {     goval bowl = new goval(10,10);     add(bowl);     addmouselisteners(); }   public void mouseclicked(mouseevent e) {         while (getwidth() > bowl.getx()+10) {         bowl.move(10.0, 0);         pause(50);     } }  private goval bowl;  } 

the line:

goval bowl = new goval(10,10); 

is declaring new goval , hiding global goval defined @ bottom.

that line should be:

bowl = new goval(10,10); 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -