I have a question here:
why am I getting a nullpointerexception in this code ?
Code:
public class Showroom{
private Vehicle stocks[];
private double width;
private double height;
private double length;
//--------------------------------
public Showroom(){
stocks[0]=new Vehicle();
stocks[1]=new Vehicle();
stocks[2]=new Vehicle();
stocks[3]=new Vehicle();
stocks[4]=new Vehicle();
width=0.0;
height=0.0;
length=0.0;
}
public void setStocks(Vehicle v, int x){
stocks[x]=v;
}
public Vehicle getStocks(int x){
return stocks[x];
}
public double calculateArea(){
return width*height*length;
}
public void setWidth(double a){
width=a;
}
public double getWidth(){
return width;
}
public void setHeight(double b){
height=b;
}
public double getHeight(){
return height;
}
public void setLength(double c){
length=c;
}
public double getLength(){
return length;
}
public static void main(String args[]){
Showroom s = new Showroom();
Vehicle myVehicle;
myVehicle = new Vehicle("abc", "green", 3, 3, 3);
s.setStocks(myVehicle, 0);
System.out.println(s.getStocks(0));
}
}
The one in red is the one that the compiler complaining about. Can you tell me what is wrong with that ? I really cant figure out what is wrong.
Thanks.
Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum