• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Declaring a variable from another class  RSS feed

 
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);
}
 
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!