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 › newbie problem :P
Page Index Toggle Pages: 1
newbie problem :P (Read 649 times)
newbie problem :P
Aug 31st, 2005, 5:26am
 
Good night...

I started a couple of days learning java (and processing). I've bumped into a problem that's driving me nutts. Here it comes:

float points[][];
String roughpt[] = loadStrings ("points.txt");
for (int i=0; i<roughpt.length; i++) {
 float bin[] = float(split(roughpt[i]));
 points[i][0] = bin[1];
 points[i][1] = bin[2];
 points[i][2] = bin[3];
}

And the log says something like this "The variable "points" may be accessed here before having been definitely assigned a value.", pointing line 5.
Does someone now where's my mistake?

Thanks a lot.

Re: newbie problem :P
Reply #1 - Aug 31st, 2005, 7:05am
 
May be:

Code:


float points[][];

void setup() // <<<
{            // <<<

 String roughpt[] = loadStrings("points.txt");
 for (int i=0; i<roughpt.length; i++) {
   float bin[] = float(split(roughpt[i]));
   points[i][0] = bin[1];
   points[i][1] = bin[2];
   points[i][2] = bin[3];
 }
}            // <<<



or without processing method

Code:


 String roughpt[] = loadStrings("points.txt");
 int num = roughpt.length;
 float points[][] = new float[num][3];
 for (int i=0; i<num; i++) {
   float bin[] = float(split(roughpt[i]));
   points[i][0] = bin[1];
   points[i][1] = bin[2];
   points[i][2] = bin[3];
 }



I hope this help you.
And (another question) which is the difference between

float[][] points = new float[num][3];
float points[][] = new float[num][3];

Thanks.
Re: newbie problem :P
Reply #2 - Aug 31st, 2005, 3:25pm
 
this error means just what it says: "The variable "points" may be accessed here before having been definitely assigned a value."

which is just that the compiler is concerned that it sees points[] in use, but there's a possibility that the code that uses points[] (inside your loop) might happen before points[] has been set to anything.

you can make the error go away by changing:
float points[][];
to
float points[][] = null;

which just tells the compiler that you know what you're doing and will assign it to something later. in your case it's a little silly, but in others, it can sometimes help prevent dumb mistakes.

float points[][] and float[][] points are identical, it's just a matter of preference. there are some minor cases where it makes a difference (float[][] pieces1, pieces2 might give you a headache) but it's generally identical.
Re: newbie problem :P
Reply #3 - Sep 1st, 2005, 3:20pm
 
Thanks to all Smiley, it works.
Page Index Toggle Pages: 1