Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

non-static variable special cannot be referenced from a static context

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to add a field (called special) to a hibernate table. I am copying existing code (related to the NAME field) so I don't have to figure this out from scratch.

I am getting the error "[ERROR] C:\VOX\voxware-1.1.13\voxware\voxware-impl\src\main\java\com\voxware\impl\flow\VoxFlowConfiguration.java:[213,38] error: non-static variable special cannot be referenced from a static context".

Line 213 is in public void mergeFrom, the actual line is "special = VoxFlowConfiguration.special;" I don't understand why Java thinks special is a "non-static" variable but it doesn't have a problem with the other variables (such as name, orderShow)

 
Sheriff
Posts: 7108
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not that special is non-static, it's that VoxFlowConfiguration.special is static.
 
Marshal
Posts: 25838
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Michael Piaser wrote:I don't understand why Java thinks special is a "non-static" variable but it doesn't have a problem with the other variables (such as name, orderShow)



That's because you haven't tried to use VoxFlowConfiguration.name or VoxFlowConfiguration.orderShow. If you looked at the place where you used those variables, you'll see that you wrote voxFlowConfiguration.name -- this says to use the public name variable of the object referred to by the variable voxFlowConfiguration. This isn't a static context because it's about an object, and so it's not a problem. However when you used the special variable you'll see that you wrote VoxFlowConfiguration.special -- this says to use the public special variable of the VoxFlowConfiguration class. And that's a static context because it's about a class, not an object.

If you still don't see the difference then let me point out that VoxFlowConfiguration and voxFlowConfiguration aren't the same thing. They are two confusingly similar names.
 
Michael Piaser
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks - basically I accidentally used the wrong case in the first letter and didn't notice it.
 
Rancher
Posts: 1041
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Michael Piaser wrote:basically I accidentally used the wrong case in the first letter and didn't notice it.



An argument against this variable naming convention.
 
Michael Piaser
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
true indeed - unfortunately it is inherited code
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic