PLZ I need a help
I have an error while running the Prog.
-------
Exception in thread "main" java.lang.NullPointerException
at Robot.main(Robot.java:20)
-------
this is my code
this is control class.
public class Control { private int x; private int y; public Control(){ this.x=0; this.y=0; } public void setX(int x){ this.x=x; } public void setY(int y){ this.y=y; } public int getX(){ return this.x; } public int getY(){ return this.y; } }
-------------------------
this is main class
/* -The program is designed to control the movement of a robot in the chemical room. Robot must not hit any room wall (10*10). * 2 robots not allowed to be located in the same place. You should expect the input errors entered by the user. */ import java.util.*; import javax.swing.*; public class Robot { public static void main(String[] args) { int i; int k =Integer.parseInt(JOptionPane.showInputDialog(null, "How many Robot you want to play with?")); Control robot[]=new Control [k]; for ( i=0; i<robot.length; i++){ int x = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter The X coordinate of the robot:")); int y = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter The y coordinate of the robot:")); robot[i].setX(x); robot[i].setY(y); System.out.println(robot[i].getX()+" "+robot[i].getY()); { if(robot[i].getX()>10 || robot[i].getY()>10){ robot[i].setX(0); robot[i].setY(0); JOptionPane.showMessageDialog(null, "Hitting wall.. \n Robot coordinate is: " + "("+robot[i].getX()+","+robot[i].getY()+")"); } else JOptionPane.showMessageDialog(null,"Robot corrdinate is:\n"+"("+robot[i].getX()+ ","+robot[i].getY()+")"); } } } }
PLZ Help me