为什么我在处理中收到此错误?

Why am I getting this error in Processing?

正在尝试在这里创建一个绘图程序,其中画笔根据 mouseX 和 mouseY 的位置改变颜色。

当我 运行 代码时不断收到此错误:

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
RuntimeException: java.lang.reflect.InvocationTargetException
at processing.core.PApplet.runSketch(PApplet.java:10852)
at processing.core.PApplet.main(PApplet.java:10620)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at processing.core.PApplet.runSketch(PApplet.java:10846)
... 1 more
Caused by: java.lang.NullPointerException
at processing.core.PApplet.fill(PApplet.java:14781)
at sketch_220306a.<init>(sketch_220306a.java:40)
... 6 more

感谢任何帮助...我对 Java 很陌生,所以您可能想用更基本的术语来解释它,解释为什么我需要更改某些内容。

/* [创建一个绘图程序,其中 'brush' 根据 window 中的位置改变颜色。] */

void setup () {
    background (128); // set background colour
    mouseX = 50; // declare initial mouse X value
    mouseY = 50; // declare initial mouse Y value
}

void draw () {
    ellipse(mouseX, mouseY, 10, 10); // 
} 
// if the value of mouseX is greater than 50 and mouseY is less than 50
{ if ((mouseX > 50) && (mouseY < 50)) {
    // fill ellipse red
    fill (255,0,0); 
} else { 
    // fill ellipse blue
    fill (0,0,128); 
}

}

我不确定 InvocationTargetException 是关于什么的。但是,您问题中的代码存在一些语法错误。这是代码,已修复:

void setup () {
  background (128); // set background colour
  mouseX = 50; // declare initial mouse X value
  mouseY = 50; // declare initial mouse Y value
}

void draw () {
  // if the value of mouseX is greater than 50 and mouseY is less than 50
  if ((mouseX > 50) && (mouseY < 50)) {
    // fill ellipse red
    fill (255,0,0); 
  } else { 
    // fill ellipse blue
    fill (0,0,128); 
  }
  ellipse(mouseX, mouseY, 10, 10);
}

我更改了一些花括号的位置,并在您设置颜色后移动了椭圆。