• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Michael Piaser
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)

 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • 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.
 
Paul Clapham
Sheriff
Posts: 22829
43
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.
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • 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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!