我知道我做错了什么,但似乎无法修复它。
class Draw {
int x,y;
int xp,yp;
PImage image;
Draw(int dragx, int dragy, int movex, int movey, PImage a) {
x = dragx;
y = dragy;
xp = movex;
yp = movey;
image = a;
}
void display() {
smooth();
background(255);
fill(255);
rect (0,180,40,40);
fill(0);
rect (0,240,40,40);
image = get();
stroke(0);
fill(255);
}
void drawing() {
background(image);
float sizex = xp - x;
float sizey = yp - y;
if (mousePressed && mouseButton == LEFT) {
rect(x, y, sizex, sizey);
}
}
void press() {
x = mouseX;
y = mouseY;
}
void release() {
xp = mouseX;
yp = mouseY;
noLoop();
image = get();
loop();
}
void drag() {
xp = mouseX;
yp = mouseY;
}
}
Draw rect;
void setup() {
size (900,600);
//rect.display();
}
void draw() {
background(255);
//rect.drawing();
}
void mousePressed() {
//rect.press();
}
void mouseReleased() {
//rect.release();
}
void mouseDragged() {
//rect.drag();
}
评论中的区域或" //"是我得到的错误,给我'NullPointerException'错误。 我想以某种方式理解我如何能够展示' void display()'在' void setup()'在Draw rect;没有任何错误。
答案 0 :(得分:2)
您尚未在任何地方初始化rect
。你应该初始化它:
void setup() {
rect = new Draw(0, 0, 0, 0, new PImage());
size (900,600);
//rect.display();
}