I'm trying tackle this problem for a few days now but with no success. Here is the code:
import java.util.*;
import java.io.*;
public class Portefeuille {
private ArrayList<Woning> woningen;
public Portefeuille(){
woningen = new ArrayList<Woning>();
}
public void voegToe(Woning w){
if(woningen.contains(w)==false)
woningen.add(w);
else
System.out.println(w.toString()+" komt al voor en is daarom niet toegevoegd.");
}
public ArrayList<Woning> woningenTot(int maxprijs){
ArrayList<Woning> totaal = new ArrayList<Woning>();
for(int i=0; i<woningen.size(); i++){
if((woningen.get(i)).KostHooguit(maxprijs))
totaal.add(woningen.get(i));
}
return totaal;
}
public static Portefeuille read(String infile){
Portefeuille woningen = new Portefeuille();
try
{
FileReader file = new FileReader(infile);
Scanner sc = new Scanner(file);
int aantalwoningen = sc.nextInt();
for(int i=0; i<aantalwoningen; i++){
Woning woning = Woning.read(sc);
woningen.voegToe(woning);
}
System.out.println(woningen.toString());
sc.close();
} catch(Exception e){
System.out.println(e);
}
return null;
}
}
And here is the main file
import java.util.*;
public class Test2 {
public static void main(String[] args){
Portefeuille bestand = Portefeuille.read("in.txt");
ArrayList<Woning> WTot = bestand.woningenTot(21500);
}
}
The error i am getting: Exception in thread "main" java.lang.NullPointerException at Test2.main(Test2.java:6)
I would really appreciate if someone could just at least point me in the right direction.
Thanks,
Jaspreet