I'm fazed by a nullpointererror I can't get rid of
Martin Platt
Greenhorn
Joined: Aug 23, 2004
Posts: 9
posted
0
It's really annoying because it seems logical enough to me and I'm sure it's something really simple. I hope someone can help me. It's a bat and ball game to which I'm adding a computer opponent. The problem occurs in the Ball code:
and throws the exception because it doesn't like aii.b. But it has no problem in the next if statement: if ((int)(x)>=490 && y>james.z-6 && y<james.z+35+6)
if you change the lines around, ball will be null - same reason
Martin Platt
Greenhorn
Joined: Aug 23, 2004
Posts: 9
posted
0
Thanks Michael, this makes sense. I see what you mean that, either way, you get the error. But I need ai to know about ball, and ball to know about ai. Is there an easy way to send this information after the object is created? [ December 28, 2005: Message edited by: Martin Platt ]
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
you could try this (need to modify ball's constructor)
//ball=new Ball(200,250,-5,-5,bat,hitwall,score,missit,ai);//remove ai ball=new Ball(200,250,-5,-5,bat,hitwall,score,missit); ai=new Ai(ball); ball.aii = ai;