Java

Moderators: zibadian
Number of threads: 7818
Number of posts: 18218

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Array of objects initialization Problem Posted by Danish Kamran on 22 Dec 2007 at 9:13 AM
As Array of primative data types or non premative data types( objects of class) are created, they are initialized.i.e.
if i do
int [] i = new int [10]; then,
Array of 10 integers is created and they are initializesd by zero and if i have a class of Name Test and i do
Name [] N = new Name[10]; then
10 Array of data type Name is created and they all iniatialized by null and if i call any method of Name like N[0].someMethod then JDK sends nullpointerexception.
Please tell me how to over come to this problem and how array of data types are created by their Actual object not by null or 0 value.
Thanks

Report
Re: Array of objects initialization Problem Posted by Jonathan on 23 Dec 2007 at 8:45 AM
Hi,

I think the best you can do is write a loop that initializes each element of the array after you've declared it.

for (i = 0; i < TheArray.Length; i++)
    TheArray[i] = new Thingy();


Or something like that; it may be a little off, since (happily ) I don't have to write Java any more these days.

Jonathan
###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.