-3

This is the place where i declare the variable and get and set methods. All are inside the same class.

public class Users 
{
    private String username;

    public void setUsername(String username) 
    {
    this.username = username;
    }

    public String getUsername() 
    {
    return username;
    }

    public static ArrayList<Users> getAllContacts(String f) {

    Users Contact;
    ArrayList<Users> ContactList = new ArrayList<Users>();
    String query = "select * from UsersDB where username = ?";
    // connect to DB
    currentCon = DBController.getConnection1();

    try {
        pstmt = currentCon.prepareStatement(query);

This is the part where it cannot make static reference to non static method, its inside the same class.

  pstmt.setString(1, getUsername()); //  Cannot make a static reference to the non-static method 
        rs = pstmt.executeQuery();
        while (rs.next()) {
            int id = rs.getInt("id");
            String name = rs.getString("name");
            int mobile = rs.getInt("phone_Number");
            String gender = rs.getString("gender");
            String email = rs.getString("email");
            String birth = rs.getString("birthDate");

            Contact = new Users(name, email, gender, mobile, birth);
            ContactList.add(Contact);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return ContactList;
}

}
user3021598
  • 35
  • 1
  • 8

1 Answers1

0

You need to call the getUsername() method from an actual Users object. Probably what you meant to do was say Contact.getUsername().

Epiglottal Axolotl
  • 1,048
  • 8
  • 17