0

Edit: I think my problem is different from the one that is similar because when I tried to split my declaration of Seat it gave me the non-static error.

I have a program to write for a class, and I created a object called Seat. However, when I try to reference it in main, it says I have a null pointer error. When I declare every item in the object array it says I can't reference the object seats from a non static standpoint. I tried a whole bunch of other questions on STackOverflow but I couldn't get any of them to work. This is what I have so far:

@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception{

    File file = new File("Customers.txt");
    Scanner input = new Scanner(file);

    Customer[] airlinecustomer;
    airlinecustomer = new Customer[40];
    Seat[] seats = new Seat[40];


     for(int i = 0;i < 40;i++) seats[i] = new Seat();

    seatssold = seatssold + input.nextInt();

    for(int i = 0;i < seatssold;i++) {

        airlinecustomer[i].firstname = input.next();
        airlinecustomer[i].lastname = input.next();
        airlinecustomer[i].DOB = input.next();
        airlinecustomer[i].email = input.next();
        airlinecustomer[i].address = input.next();
        airlinecustomer[i].telephone = input.next();
        airlinecustomer[i].seat = input.nextInt();

        seats[i].customer = i;
        seats[i].available = "S";

    }

    //for(int i = 0;i < 40;i++) if(seats[i].available != "S") seats[i].available = "U"; 


}

public class Customer {

    private String firstname;
    private String lastname;
    private String DOB;
    private String email;
    private String address;
    private String telephone;
    private int seat;

        public Customer(String firstname,String lastname,String DOB,String email,String address,String telephone,int seat) {

            this.firstname = firstname;
            this.lastname = lastname;
            this.DOB = DOB;
            this.email = email;
            this.address = address;
            this.telephone = telephone;
            this.seat = seat;
        }
}

public static class Seat {

    static String available;
    static int customer;

        public Seat(String available,int customer) {

            this.available = available;
            this.customer = customer;
        }
}

}

I'm sorry if this is confusing but I just have no idea what to do, I have only been coding for a few months.

Thanks so much :)

0 Answers0