How can I add an Object to its Array??? When I create an instance of a Class and try to assign it to its array it gives me a Null Pointer Exceptions .... the line below in BOLD is where I get the exception.
Is this legal in Java??? if Yes, why am I getting a Null Pointer Exception, or is there something else I need to do ???
All suggestions are greatly accepted and thanked for.
Mark Van Tuyl
Ranch Hand
Joined: Mar 22, 2002
Posts: 60
posted
0
You have declared the array but never instantiated it with the new keyword.
You need to do something like this:
private Authorization authorizaition[] = new Authorization[42];
<a href="http://www.catb.org/~esr/faqs/smart-questions.html" target="_blank" rel="nofollow">How To Ask Smart Questions</a>
Sam Nanda
Greenhorn
Joined: Jan 20, 2005
Posts: 15
posted
0
Originally posted by Mark Van Tuyl: You have declared the array but never instantiated it with the new keyword.
You need to do something like this:
private Authorization authorizaition[] = new Authorization[42];
Thanks Mark , it helps .... Appreciate it.
Ernest Friedman-Hill
author and iconoclast
Marshal
declares an array variable, but does not create the physical array object; the variable remains null. You have to actually create the array: for example,
private Authorization authorization[] = new Authorization[NUMBER_OF_AUTH];
Finally; please stop starting new threads regarding this single problem. Any followup should go in this original thread. Thanks for helping keep the Saloon neat and clean!