I cannot add any (or maybe just the first?) Objects to my Arraylist
A Bikestore is an Object which contains a name and an Arraylist of all it's bikes
bikes have 3 different attributes (2 Strings, 1 double)
Bikes are added to the Store within an "addbiketocollection()" method and within this method I use the .add function.
public class Bikes
String brand ;
String color;
double price;
Bike(String brand, String color, double price){
this.brand = brand;
this.color = color;
this.price = price;
}
public class Bikestore {
String name;
ArrayList<Bike> Collection = new ArrayList<>();
Bikestore (String name, ArrayList<Bike> Collection){
this.name = name;
this.Collection = Collection;
}
public void AddBikeToCollection (Bike NewBike) {
Collection.add(NewBike);
}
Mainclass
Bike Bike1 = new Bike ("Cube", "Black", 400);
Bikestore SellingBikes = new Bikestore ("SellingBikes", null);
SellingBikes.AddBikeToCollection(Bike1);
}
when I try to add bikes to the bikestore I get a nullpointerxception Exception in thread "main" java.lang.NullPointerException
I have already googled my problem and watched some videos but none of these contained an arraylist with objects.