Hello i am trying to add my Class's objects into an ArrayList with the objects attributes but i keep getting null pointers I am reading values from a txt file assigning them to the attributes and then put the object into the array list
here is my code
public class Users {
Scanner scan;
BufferedReader reader;
MainGui gui;
Login login;
String name;
String surname;
String dob;
String address;
String town;
String number;
String position;
ArrayList<Users> allUsers = new ArrayList<Users>();
public Users(Login login){
this.login = login;
open();
}
public void open(){
try {
URL path = Users.class.getResource("records.txt");
File f = new File(path.getFile());
reader = new BufferedReader(new FileReader(f));
scan = new Scanner(reader);
} catch (FileNotFoundException e) {
System.out.println("File not found");
}
}
public void readRecords(){
open();
while(scan.hasNext()){
Users user = new Users(login);
user.name = scan.next();
user.surname = scan.next();
user.dob = scan.next();
user.address = scan.next();
user.address = addSpace(user.address);
user.town = scan.next();
user.number = scan.next();
user.position = scan.next();
allUsers.add(user);
}
scan.close();
}
public void printUsers(){
readRecords();
for(Users user : allUsers){
System.out.println("" + user );
}
}
}
I have included all the methods playing part in this in order for you to help me better.