• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

fix for non-static variable

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a compile error that says "non-static variable frame cannot be referenced from a static content. frame = new Tickerframe();". I have this in a public method, in a public class. I have a statement "TickerFrame frame;" before the method. What do I need to do to fix the problem?
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't be 100% sure without seeing your code, but I imagine that you have some code like the following:

This will not compile because the frame variable is an instance variable on the MyClass class; that is, in order to have access to the frame variable, you need to first create a MyClass object to hold it. There are a couple of solutions to this problem; what you need depends on how you use the variable.
1). If the frame variable isused only in the one method, declare the frame variable inside the static method. That would look like:


2). If other methods of MyClass use the frame variable, create an instance of MyClass.


3). If you method should not be static, remove the static attribute from the method. (This doesn't work for the main method; it must be static).
[ April 09, 2003: Message edited by: Joel McNary ]
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic