aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes SWT: Why do I get Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "SWT: Why do I get "MeterToInch2.java:24:5: non-static variable label cannot be.."? " Watch "SWT: Why do I get "MeterToInch2.java:24:5: non-static variable label cannot be.."? " New topic
Author

SWT: Why do I get "MeterToInch2.java:24:5: non-static variable label cannot be.."?

Andreas Balzer
Greenhorn

Joined: Apr 06, 2008
Posts: 12
Hi,
See http://pastebin.com/m56869c2e
I get errors like this:
MeterToInch2.java:23:5: non-static variable label cannot be referenced from a static context

Why is it thrown and how to solve it? Also do I have to take care about something else or is this program capable of running?

Thanks for any help

Greetings,
Andreas
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39543
    
  27
You can't access instance fields (like label and eingabeleiste) from a static method like main. You need to instantiate a MeterToInch2 object, and then reference them through it, like

By the way, it's easier to post snippets of code here, using CODE tags. That way everybody knows right away what we're talking about.


Ping & DNS - updated with new look and Ping home screen widget
Andreas Balzer
Greenhorn

Joined: Apr 06, 2008
Posts: 12
ah alright. I have chosen to make the variables static.. Aem. The error is now gone but unfortunately the window opens and closes immediatly. Somehow the loop doesn't work. What's wrong with that?

Update: The dispose was in the loop. It has to be below..
[ April 06, 2008: Message edited by: Andreas Balzer ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SWT: Why do I get "MeterToInch2.java:24:5: non-static variable label cannot be.."?
 
Similar Threads
Polymorphic Method Call
JLabel and JTextField not showing up
Best Place to Store Temp Code Snippets Online?
How do you compile java program?
i cannot be resolved to a variable