We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm getting a NPE in my code, but i fail to see what i'm doing wrong.
NPE@line 7
class Card {
String id;
int amount;
int colour;
int shape;
int fill;
PGraphics face = createGraphics(100,100);
int xPos;
int yPos;
Boolean selected = false;
Card (int preamount, int precolour, int preshape, int prefill){
amount = preamount;
colour = precolour;
shape = preshape;
fill = prefill;
id = str(preamount)+str(precolour)+str(preshape)+str(prefill);
// face = createGraphics(100,100);
face.beginDraw();
face.background(0,0);
face.noStroke();
face.fill(255);
face.rect(2,2,96,96,10);
face.stroke(colours[colour]);
face.fill(colours[colour],pow(15,fill));
int drawing = (amount << 2)|shape;
switch(drawing){
case 0:
face.triangle(50,20,80,80,20,80);
break;
case 1:
face.ellipse(50,50,80,60);
break;
case 2:
face.rect(20,40,60,20);
break;
case 4:
face.triangle(15,15,55,15,35,55);
face.triangle(85,85,45,85,65,45);
break;
case 5:
face.ellipse(50,30,60,30);
face.ellipse(50,70,60,30);
break;
case 6:
face.rect(20,25,60,20);
face.rect(20,55,60,20);
break;
case 8:
face.triangle(15,15,45,15,30,45);
face.triangle(55,15,85,15,70,45);
face.triangle(35,55,65,55,50,85);
break;
case 9:
face.ellipse(35,20,60,30);
face.ellipse(50,50,60,30);
face.ellipse(65,80,60,30);
break;
case 10:
face.rect(20,10,60,20);
face.rect(20,40,60,20);
face.rect(20,70,60,20);
break;
}
face.endDraw();
}
}
As you can see, I've tried moving the createGraphics() to the same line that I define it at, but that throws me the same error.
Answers
I don' see any obvious problems within your class. Where is the rest of the code? I suppose the problem starts there.
Here's the rest:
By the way, I'm using processing 2.2.1, if that matters
You should not name your function "init", this seems to be used by processing 2.2 internally. Renaming it should fix your problem. (In 3x it actually works..)
Huh. Usually they mark internal functions as blue, but I'll try that.
That seems to have fixed it, thanks!