• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Cannot make a static reference to the non-static type

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:



 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 80093
413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you using compareTo and not equals() in your equals() method?
 
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic