Advertisement

[java] What causes this code to break?

Started by January 17, 2001 11:11 AM
7 comments, last by Eraserhead 24 years ago
This piece of code is driving me nuts! I know it's probably simple but...:
    
private void createShots()
   {
      shots=new Shot[NO_POOLED_SHOTS];
      for (int i=0; i<NO_POOLED_SHOTS; i++)
      {
         shots[i]=new Shot(rctGame);
         actorList.addSprite(shots[i]);
      }
   }
    
The line
  actorList.addSprite(shots[i])  
throws a nullpointerexception at me (at the first iteration of the loop), and I can't figure out why. I have traced through it with a debugger, and I know shots[0] isn't null when I reach that line. Any thoughts? Edited by - Eraserhead on January 17, 2001 12:14:19 PM
Silly question, but are you sure actorList been instantiated? In other words is there a line somewhere before the call to createShots that says actorList = new ActorList(.....)?
Advertisement
check out actorlist

maybe that is null , or maybe addsprite itself is throwing the exception..


umm...never mind... < knocks himself over the head with a large wet fish >

Edited by - Eraserhead on January 18, 2001 1:20:44 AM
quote:
Original post by Eraserhead

umm...never mind... < knocks himself over the head with a large wet fish >

Edited by - Eraserhead on January 18, 2001 1:20:44 AM


Just a question. What was the problem?
I''m still learning this stuff, and it''s always good to see the answer to the problem.


BeS
It''s Da BOMB Baby!!!
BeSIt's Da BOMB Baby!!!. o O ~ A little nonsense now and then,is relished by the wisest men~ O o .-- Willy Wonka
uhhmm...well, as these guys kindly suggested to me, and as I discovered myself 5 minutes after making the initial post, the actorList pointer isn''t valid. Can you believe I looked at this code for 45 minutes without figuring that out? <slaps himself once more over the head with the (now) rotten fish>
The problem was that this method was called from another place than I thought, before the actorList had been instantiated.

I deeply apologize for bothering you all with this.
Advertisement
I have had those days

joeG

joeG
Trust me, you''re not alone.

Try making a canvas then forgetting to add it and pondering for about a day till a friend has to point it out to you.

Sad but true. We live and we (hopefully) learn.

Smoo
That''s nothing. Just wait till you write some code, come back to it a few weeks later - then have to assume you must have been on drugs, because you can''t, for the life of you, figure out why you did it that way in the first place.

This topic is closed to new replies.

Advertisement