Trouble using access functions in an array of objects

From: Aki Laukkanen (aki.laukkanenREMOVE_THIS_at_helsinki.fi)
Date: 05/31/04


Date: Mon, 31 May 2004 16:14:57 +0300

Okay, here's what i've got stuck with this time:
I have an array of objects, and I want to set properties of each object
in the array using the objects' access function.
While doing this, i get a NullPointerException.
What am I doing wrong?

Example of the code:

class Member {
        private long aValue;
        public void SetAValue(long aValue){
                this.aValue = aValue;
        }
}
//The following is written in the main function of another class:
Member[] Members = new Member[10];
for(int i = 0; i < 10; i++){
        Members[i].SetAValue(5);
}

-- 
-Aki "Sus" Laukkanen


Relevant Pages

  • Re: Best Coding Practice
    ... I needed to add an array class member to an object. ... public function addArrayA{ ... later I was cursing the programmer that came up with this ...
    (comp.lang.php)
  • Best Coding Practice
    ... let me say that this question is a rather general programming ... I needed to add an array class member to an object. ... public function addArrayA{ ...
    (comp.lang.php)
  • Re: Best Coding Practice
    ... |> I needed to add an array class member to an object. ... where IProduct is an interface having all of those shared attributes. ... the 'order' object couldn't care less. ...
    (comp.lang.php)
  • Re: Best Coding Practice
    ... same as another class member, except that one array stored regular ... needed a way to add products to the new, free array. ... products (products that cost money, free products & products we have to ...
    (comp.lang.php)
  • Re: ATL/COM memory management
    ... but with that instance having a member array ... > properties which are typed to this separate class. ... the array is to be a class member. ... In C++ one would make the class member a pointer, then allocate in ...
    (microsoft.public.vc.language)