You are using variables out of scope. The private variables that you declare in the Actor object are only available within the class, not to any object that inherits the Actor class.
When you declare the same variables in the Fighter object, they are different variables even though they are named the same. It then gets a null pointer because the variables in the Actor class are never set.
Just change the variables in the Actor class to be public and remove the variables from the Fighter class as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| public class Fighter extends Actor{ public Fighter(Node node){ System.out.println("MAR"); src = "/resources/fighter.gif"; path = new ArrayList<Node>(); open = new ArrayList<Node>(); closed = new ArrayList<Node>(); this.node = node; this.node.setActor(this); target = null; speed = 2; x = node.getCentreX(); y = node.getCentreY(); ImageIcon ii = new ImageIcon(this.getClass().getResource(src)); image = ii.getImage(); width = image.getWidth(null); height = image.getHeight(null); } } public class Actor{ public Node node, target; public int x, y, width, height; public Image image; public String src; public double speed; public ArrayList<Node> path; public ArrayList<Node> open; public ArrayList<Node> closed; public Actor(){ } ... insert methods here ... } |