Random class (problem with pointer :/ )
Hi all.
Second question for today.
I am new with Java. I would like to use a Random class. But I am facing a problem with pointer(Null pointer).
\\new random:
Random random=new Random();
\\new floats:
float x=random.nextFloat();
float y=random.nextFloat();
float z=random.nextFloat();
[540 byte] By [
America70a] at [2007-11-26 15:53:06]

Point3f points[]=new Point3f[tN];
Random random=new Random();
for(int i=0;i<N;i++){
points[i].x=random.nextFloat();
points[i].y=random.nextFloat();
points[i].z=random.nextFloat();
}
points[N]=points[0];
>
> I forgot to show you first line:
It doesn't matter. Look at this example:
String[] strArray = new String[5];
for(int i=0; i<strArray.length; i++)
{
System.out.println(strArray[i].length());//NullPointerException
}
In this example, the array of Strings was initialized, but not the Strings themselves. Now look at this example:>
String strArray = new String[5];
for(int i=0; i<strArray.length; i++)//>
{
strArray[i] = "abc";
}
for(int i=0; i<strArray.length; i++)
{
System.out.println(strArray[i].length());//No error
}
In this example, each object in the array was initialized, so no NullPointerException is thrown.>