POV-Ray : Newsgroups : povray.off-topic : Any Java experts? : Any Java experts? Server Time
10 Oct 2024 23:18:32 EDT (-0400)
  Any Java experts?  
From: Gail Shaw
Date: 17 Jan 2008 14:05:25
Message: <478fa6f5@news.povray.org>
Is there anyone who can tell me why the following code sometimes (not
always) throws a NullPointerException
Using Java(TM) SE Runtime Environment (build 1.6.0_02-b06)

Node currentNode = Universe.space[i][j]; // Have checked and this is never
null.
if (currentNode.hasShip()) { // <-- This line sometimes throws a
NullPointerException
g.drawChars(Labels, 0, 1, i*GridSizeX+GridSizeX/2, j*GridSizeY);
}
if (currentNode.hasAsteroid() ) {
g.drawChars(Labels, 1, 1, i*GridSizeX+1, j*GridSizeY);
}


And here's an abbreviated version of the Node class. The local variable
localShip is never instantiated.
public class Node {


private Ship localShip;
private Asteroid localAsteroid;

boolean hasAsteroid() {
if (localAsteroid!=null)
return true;
else
return false;
}


boolean hasShip() {
if (localShip!=null)
return true;
else
return false;
}

}


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.