Paul Clapham wrote:That's this line of code, right?
That could throw the NPE if:
(1) geo is null (we know it isn't because it refers to a Geometry object)
(2) geo.vertices is null
(3) geo.vertices[i] is null
(4) original is null (but it was used in an earlier line so we know it isn't)
(5) original.vertices is null (but it was used earlier so we know it isn't)
(6) original.vertices[i] is null (but it was used earlier so we know it isn't)
In other words, when you create a new Geometry, that doesn't initialize the "vertices" variable so that it refers to an array of the right length. Perhaps the Geometry class has a different way for adding elements to "vertices", or setting them up, or whatever.
By the way I don't understand why your transformAndRender method creates two copies of a Geometry object and does different things to each of them.
>Paul Clapham wrote:
(2) geo.vertices is null
(3) geo.vertices[i] is null
Paul Clapham wrote:Okay. So that buildGlobe() method is how you set up the vertices and faces variables in a Geometry object. So therefore your copy constructor should call it (with the correct parameters) to set up those variables in the copy, rather than trying to replicate that logic yourself.
Shawn Ma wrote:I don't want to use that method because it will not give me correct values from there.
I want to copy values from an existing object, ,,,what do I need to do before assigning values of array elment by element ???
Paul Clapham wrote:
Shawn Ma wrote:I don't want to use that method because it will not give me correct values from there.
How can it not give you the correct values? It only takes the two parameters, all of the values are derived from them.
I want to copy values from an existing object, ,,,what do I need to do before assigning values of array elment by element ???
However I suppose you haven't mentioned yet that there are other methods which allow you to fiddle with the contents of those arrays after they are assigned. Fine. Then your copy constructor should (1) create the arrays (2) copy the correct values into them. You already have step (2) programmed. I already told you how to do step (1). Do them in the right order.
Don't get me started about those stupid light bulbs. |