• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot make a static reference to the non-static type  RSS feed

 
Meg Berg
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am working on using linked lists. My project will include a UI, but I am trying to check that my class is doing what I expect it to but adding a main method and printing to the console. My object is AntiqueInfo and I am using my Node class to manage the list. When I try to add new AntiqueInfo items in the Node class in the main method, I am getting the error: Cannot make a static reference to the non-static type

The same code works in the AntiqueInfo class and I just don't understand what I did in the Node class that makes the AntiqueInfo not static.

Here's my code:



 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the exact error message you get? What are the package and import statements you use at the top of the classes?
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This confusion is due to a naming conflict between the type parameter of the Node class and the name of the AntiqueInfo class. It is the type parameter that the main method of the Node class refers to. Try renaming the type parameter of the Node class to T. That will solve the naming conflict and allow you to refer to the AntiqueInfo class by it's simple name from the main method of the Node class. You may have to add an import for the AntiqueInfo class in the Node class first though, depending on whether or not they are in the same package. Please refer to the tutorial section on generic types (and the generics tutorial as a whole) for more information.
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using compareTo and not equals() in your equals() method?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!