• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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

 
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:



 
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?
 
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.
 
Marshal
Posts: 60136
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using compareTo and not equals() in your equals() method?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!