[Logo]
Forums Register Login
Declaring a variable from another class
I have two classes. The first has 4 arrays I would like to use in the other class. What is the syntax for doing this I keep getting a nullpointer exception. The one class is called Final and the other is Project.
for(int i = 0; i< Final.arr.length; i++)
{
g.setColor(Color.BLUE);
g.drawOval((int)Final.arr[i], (int)Final.arr2[i], 10,10);
}
 

Originally posted by Donna Bachner:
I have two classes. The first has 4 arrays I would like to use in the other class. What is the syntax for doing this I keep getting a nullpointer exception. The one class is called Final and the other is Project.
for(int i = 0; i< Final.arr.length; i++)
{
g.setColor(Color.BLUE);
g.drawOval((int)Final.arr[i], (int)Final.arr2[i], 10,10);
}




From your code I see that arr is a static member of Final class. May be we'll have better idea, if you post code of Final class as well.

NullPointerException comes when the object you are trying to use has not been intialized. Make sure that arr is intialized properly in Final class (during declaration or in static{} block).


Jass
I fixed the problem. I did not have the set and get set up.

This thread has been viewed 505 times.

All times above are in ranch (not your local) time.
The current ranch time is
Dec 18, 2018 12:23:33.