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 › New to Processing
Page Index Toggle Pages: 1
New to Processing (Read 802 times)
New to Processing
Jun 7th, 2007, 9:47am
 
Hello,

I am new to using processing and I don't understand the errors that I am getting. Is there a list somewhere that has a breakdown of what the likely causes of error messages are?

specifically the error is a nullpointerexception in the following code


/* Reads values from a text file*/
//size(800,1000);

// load text file
String[]  tags= loadStrings("tag.txt");
String[] weights = loadStrings("weights3.txt");
// convert strings to numbers
int[] tag = int(tags);
int[] weight = int(weights);
int j = 0;

void setup() {
 size(800,400);
 background(255);
 smooth();
}
void draw() {
// For every value draw an ellipse
for (int i = 0; i < tag.length; i++) {
 j=j+tag[i];
 ellipseMode(CENTER);
 fill( weight[i],  tag[i]/weight[i], tag[i], 255);//(tag[i], tag[i], tag[i], 100)
 ellipse(width/2, j, weight[i] , tag[i]); //(width/2,j, weight[i], tag[i])
}
}

thanks very much
Re: New to Processing
Reply #1 - Jun 7th, 2007, 10:55am
 
Copy out the entire error and post it.

A null pointer means you're asking for a value that hasn't been defined. Either it can't find those text files or it doesn't like initialising values outside of setup.
Re: New to Processing
Reply #2 - Jun 7th, 2007, 3:46pm
 
Hi, just have the same problem trying to open the txt file before the setup function working a another project. After cut & pasting the text file's operation in draw everething works. I'ven't test your code but i think i'd work like that.
Re: New to Processing
Reply #3 - Jun 7th, 2007, 6:59pm
 
Thanks for the help, moving the variables inside of draw fixed the problem.
Re: New to Processing
Reply #4 - Jun 7th, 2007, 8:05pm
 
jared,

you probably want to do the loading in setup not draw, as it only needs to happen once I assume.

something like this should work (and be a little more efficient.)

Code:

// load text files

// these variables have global scope
int[] tag, weight;

void setup() {
size(800,400);
background(255);
smooth();
// you can combine loading and casting in one expression
tag = int(loadStrings("tag.txt"));
weight = int(loadStrings("weights3.txt"));
}

void draw() {
// For every value draw an ellipse
for (int i=0, j=0; i<tag.length; i++) {
fill(weight[i], tag[i]/weight[i], tag[i], 255);
ellipse(width/2, j, weight[i], tag[i]);
j+=tag[i];
}
}




*** I modifed this. I noticed you weren't reinitializing j, so I declared it in for loop head.
Re: New to Processing
Reply #5 - Jun 10th, 2007, 12:12am
 
*** I modifed this. I noticed you weren't reinitializing j, so I declared it in for loop head. [/quote]

j shouldn't get initialized it's being used as a new variable

thanks for the advice though
Page Index Toggle Pages: 1