• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Declaring a variable from another class

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I fixed the problem. I did not have the set and get set up.
 
reply
    Bookmark Topic Watch Topic
  • New Topic