• Post Reply Bookmark Topic Watch Topic
  • New Topic

Declaring a variable from another class  RSS feed

 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
 
Jass Singh
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I fixed the problem. I did not have the set and get set up.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!