Hello,
I have a simple World with two Actors, Auto and Zielsichrakete(Homing Missile) I try to make a Homing Missile, that needs the coordinates from a Auto Object. When trying to get the Reference i am getting a NullPointerException in class Zielsuchrakete.
Class Zielsuchrakete
Class MyWorld
Can someone help me out?
Best wishes and a great day,
Sebastian
public class Zielsuchrakete extends Actor { private Auto target; private int deltaX; private int deltaY; private int geschwindigkeit = 5; public Zielsuchrakete() { this. target = this.getWorld().getObjects(Auto.class).get(0); } /** * Act - do whatever the Zielsuchrakete wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { // move(-1); // if(isAtEdge()) turn(180);// this.setLocation(this.getX() - this.deltaX*this.geschwindigkeit/(this.deltaX*this.deltaX), this.getY()+this.deltaY * this.geschwindigkeit/(this.deltaX + this.deltaY)); // // Add your action code here. } }
public class MyWorld extends World { /** * Constructor for objects of class MyWorld. * */ public MyWorld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(800, 600, 1); this.addObject(new Auto(), 0, getHeight()/2); this.addObject(new Zielsuchrakete(), getWidth(), getHeight()/2); } }