We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › nullPointerException
Page Index Toggle Pages: 1
nullPointerException (Read 488 times)
nullPointerException
Mar 20th, 2007, 4:41am
 
hey, got something here thats truly bugging me out... maybe someone can take a look? (i already know that the .tif's won't work, they are just in my data folder as place holders for now.)

tab1: skyeSelf

// variables
int introLineY, ySpot, x, y;
PImage[] Zones = new PImage[7];
PImage maskMe;
triggerPoint tP = new triggerPoint();



void setup()
{
 Zones[0] = loadImage("48.tif");
 Zones[1] = loadImage("54.tif");
 Zones[2] = loadImage("86.tif");
 Zones[3] = loadImage("103.tif");
 Zones[4] = loadImage("128.tif");
 Zones[5] = loadImage("136.tif");
 Zones[6] = loadImage("158.tif");
 println ("y[6]");
 size(800,533);
 x=width;
 y=height;
 tP.fillX();
 tP.fillY();
 background (0);
}

void draw()
{
 strokeWeight (3);
 stroke (#930000);
 line (width/2, height/2-40, width/2, height/2+40);
}

---------

tab2: toolBox

class toolBox {
 int minColorVal = 0;
 int maxColorVal = 255;
 int hCenter;           // horizontal center of screen
 int vCenter;           // vertical center of screen
 
// constructor
 toolBox() {
   hCenter = width/2;
   vCenter = height/2;
 }
 
// generating a random integer between and including minVal and maxVal
 int randomInt(int minVal, int maxVal) {
   return int(random(minVal, maxVal+1));  
 }

// generating a color with random R, B, and B values
 color randomColor() {
   return color(
     randomInt(minColorVal, maxColorVal),  // random R value
     randomInt(minColorVal, maxColorVal),  // random G value
     randomInt(minColorVal, maxColorVal)   // random B value
   );
 }

// generate color with random hue value
 color randomHueColor() {
   colorMode(HSB, 360);
   return color(
     randomInt(minColorVal, 360),   // random Hue
     360,                           // full Saturation
     360                            // full Brightness
   );            
 }

// generate color with random saturation value
 color randomSaturationColor(int hueVal) {
   colorMode(HSB, 360);
   return color(
     hueVal,                        // specified Hue
     randomInt(minColorVal, 360),   // random Saturation
     360                            // full Brightness
   );            
 }

// generate color with random brightness value
 color randomBrightnessColor(int hueVal) {
   colorMode(HSB, 360);
   return color(
     hueVal,                        // specified Hue
     360,                           // random Saturation
     randomInt(minColorVal, 360)    // full Brightness
   );            
 }
}

--------------

tab3: triggerPoint

class triggerPoint
{
 int x[];
 int y[];
 toolBox tB = new toolBox();
 
 
 void fillX()
 {
   x[0] =tB.randomInt(0,800);
   x[1] =tB.randomInt(0,800);
   x[2] =tB.randomInt(0,800);
   x[3] =tB.randomInt(0,800);
   x[4] =tB.randomInt(0,800);
   x[5] =tB.randomInt(0,800);
   x[6] =tB.randomInt(0,800);
 }

 void fillY()
 {
   y[0] =tB.randomInt(0,600);
   y[1] =tB.randomInt(0,600);
   y[2] =tB.randomInt(0,600);
   y[3] =tB.randomInt(0,600);
   y[4] =tB.randomInt(0,600);
   y[5] =tB.randomInt(0,600);
   y[6] =tB.randomInt(0,600);

 }
}

----------

here is the error i'm getting:

java.lang.NullPointerException

at Temporary_7668_1549$triggerPoint.fillX(Temporary_7668_1549.java:218)

java.lang.NullPointerException


at Temporary_7668_1549.setup(Temporary_7668_1549.java:37)

at processing.core.PApplet.handleDisplay(PApplet.java:1281)

at processing.core.PGraphics.requestDisplay(PGraphics.java:564)

at processing.core.PApplet.run(PApplet.java:1450)

at java.lang.Thread.run(Thread.java:613)


at Temporary_7668_1549$triggerPoint.fillX(Temporary_7668_1549.java:218)

at Temporary_7668_1549.setup(Temporary_7668_1549.java:37)

at processing.core.PApplet.handleDisplay(PApplet.java:1281)

at processing.core.PGraphics.requestDisplay(PGraphics.java:564)

at processing.core.PApplet.run(PApplet.java:1450)

at java.lang.Thread.run(Thread.java:613)
Re: nullPointerException
Reply #1 - Mar 20th, 2007, 7:50am
 
You've not declared the sizes of he arays in your triggerpoint class.

Code:
 class triggerPoint
{
int x[];
int y[];
toolBox tB = new toolBox();


void fillX()
{
x=new int[7]; // <--
x[0] =tB.randomInt(0,800);
x[1] =tB.randomInt(0,800);
x[2] =tB.randomInt(0,800);
x[3] =tB.randomInt(0,800);
x[4] =tB.randomInt(0,800);
x[5] =tB.randomInt(0,800);
x[6] =tB.randomInt(0,800);
}

void fillY()
{
y=new int[7]; // <--
y[0] =tB.randomInt(0,600);
y[1] =tB.randomInt(0,600);
y[2] =tB.randomInt(0,600);
y[3] =tB.randomInt(0,600);
y[4] =tB.randomInt(0,600);
y[5] =tB.randomInt(0,600);
y[6] =tB.randomInt(0,600);

}
}
Page Index Toggle Pages: 1