N
Newbie
My code is as below, however, as I'm new to java, I cant quite understand
why I'm getting a "NullPointerException" with the line marked inside the
asterisks.
Could someone tell me where I'm going wrong please?
thankyou.
----------------------------------
CODE
----------------------------------
public class MyProject
{
int r1, r2;
Tractor[] trackObj = new Tractor[50]; //create array of objects from the
external tractor class
public MyProject()
{
for (int i=0; i < 50; i++)
{
//**************************************************************************
********
trackObj.setP( Randomizer() ); //call setP(int) inside
tractor class
//**************************************************************************
********
System.out.println(i+" : "+trackObj); // println only testing
input results of setP() using the toString() method
}
}
public int Rand()
{
r1 = (int)(Math.random() * 100000);
r2 = r1 / 100;
return r2;
}
}
why I'm getting a "NullPointerException" with the line marked inside the
asterisks.
Could someone tell me where I'm going wrong please?
thankyou.
----------------------------------
CODE
----------------------------------
public class MyProject
{
int r1, r2;
Tractor[] trackObj = new Tractor[50]; //create array of objects from the
external tractor class
public MyProject()
{
for (int i=0; i < 50; i++)
{
//**************************************************************************
********
trackObj.setP( Randomizer() ); //call setP(int) inside
tractor class
//**************************************************************************
********
System.out.println(i+" : "+trackObj); // println only testing
input results of setP() using the toString() method
}
}
public int Rand()
{
r1 = (int)(Math.random() * 100000);
r2 = r1 / 100;
return r2;
}
}