Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

non-static method add(java.lang.Object) cannot be referenced from a static context

 
Carrie Hadler
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I'm working on a java assignment for school and I keep getting this one error message. My teacher gave us an abstract class that includes two abstract methods and a HashSet. We have to extend the abstract class and define these methods. When I try a command like:
HashSet.add(new apple())
or
HashSet.size()
in one of the methods I am defning, I get these errors:
non-static method add(java.lang.Object) cannot be referenced from a static context
non-static method size() cannot be referenced from a static context
Does anyone know what's going on?
 
Carrie Hadler
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh nevermind. I misread a variable name. All fixed now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic