-3

I have User class with field like login, password etc.

In method i tryed to get acces to field:

preparedStmt.setString(1, User.getid());

but is the error

non static method cannot be referenced from a static context
Adamo
  • 586
  • 1
  • 9
  • 28
  • Well presumably `User.getId()` is an instance method - you've got to indicate *which* user's ID you want... – Jon Skeet Nov 09 '14 at 09:09
  • In future, please search before asking a question - in this case, to find the duplicate I just put the error message into Stack Overflow, and it found *lots* of hits. (This is a fairly common issue.) – Jon Skeet Nov 09 '14 at 09:46

1 Answers1

1

getid() is not static and therefore can only be called on an instance of User, not on User itself.

User someUser = ...;
preparedStmt.setString(1, someUser.getid());
NPE
  • 486,780
  • 108
  • 951
  • 1,012