Following Question. I have a big amount of ArrayList attributes
(basically the same as Kreuzlagerort20kg
etc). Instead of initializing them all in the constructor (the part commented out) i'd love to initialize them inside the fillLager()
method, making it possible to call the method inside the constructor and have them initialized and filled then. If i do it in the code, i always get a nullpointerexception.
Is it possible and/or sensible to initialize an arraylist inside a method, without getting said nullpointer?
import java.util.ArrayList;
public class Lager {
private ArrayList<Screws> KreuzLagerort20kg,KreuzLagerort50kg;
public Lager(){
//KreuzLagerort20kg = new ArrayList<Screws>();
//KreuzLagerort50kg = new ArrayList<Screws>();
fillLager(1,KreuzLagerort20kg,20);
fillLager(1,KreuzLagerort50kg,50);
}
public void fillLager(int typ,ArrayList<Screws> lager,double lagerGewicht){
lager = new ArrayList<Screws>();
// code that loops through combinations and adds them to the arraylist
}}}}}}