Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

[java] instatiating a class as an array

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 fabel   Members   

122
Like
Likes
Like

Posted 16 April 2000 - 10:12 PM

Hey all just a quick question, from all my poking and prodding of java there is one thing it appears it can''t do and Im hoping i''m wrong. anyways say I have a class class point3d { double x; double y; double z; public point3d() { x = y = z = 0.0; } if I do point3d[] blah = new point3d[10]; and then try and access blah[2].x i get a null pointer exception. im just curious if there is a way to do this? I know you can with the base objects in Java, strings, ints and such but that is all native code I believe. I allready found a work around for my problem but it would be nice to know if I was wrong or not on this. Tim Holwig fabel@mindspring.com

#2 SiCrane   Moderators   

11762
Like
Likes
Like

Posted 16 April 2000 - 10:28 PM

Well I believe that actually
point3d[] blah = new point3d[10];
creates an array of 10 point3d *references*, not objects. As references they are properly initialized to null. I''m pretty sure that once you created the reference array, you need to intialize the references to objects by looping through and calling the proper constructors.

#3 felonius   Members   

122
Like
Likes
Like

Posted 16 April 2000 - 11:17 PM

And to eleborate: you have to write something like (please ignore any syntax errors):


point3d[] blah = new point3d[10];

for (int i=0;i<10;i++)
blah[ i ] = new point3D();

blah[2].x; // No error!


Edited by - felonius on 4/17/00 5:21:21 AM




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.