Hi, i am a newbie at this and i am having problems with the following errors.
U:\year 3\AssignmentFinal\Customer2.java:29: non-static method setName(java.lang.String) cannot be referenced from a static context
i have inserted my code below any help would be greatly appreciated.
// customer class
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
public class Customer2 {
private String name;
private String address;
private String customerNumber;
private String emailAddress;
private String password;
public static void main(String[] args) {
List<Customer> list = new ArrayList<Customer>();
File file = new File("Customers.txt");
try {
BufferedReader in = new BufferedReader(new FileReader(file));
String line = null;
while ((line = in.readLine()) != null) {
String[] record = line.split(",");
Customer customer = new Customer();
Customer2.setName(record[0]);
Customer2.setAddress(record[1]);
Customer2.setCustomerNumber(record[2]);
Customer2.setEmailAddress(record[3]);
Customer2.setPassword(record[4]);
list.add(customer);
}
}
catch (Exception e) {
e.printStackTrace();
}
//for(Customer2 c : list){
// System.out.println(c.getName());
// }
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCustomerNumber() {
return customerNumber;
}
public void setCustomerNumber(String customerNumber) {
this.customerNumber = customerNumber;
}
public String getEmailAddress() {
return emailAddress;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}