• 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 ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Trouble with runnable and inner classes

Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new to Java and am having some trouble with runnable in conjunction with inner classes. I was able to get the code to work until I made the the gui runnable. once I did that I get the following error:

"No enclosing instance of type Temperature is accessible. Must qualify the allocation enclosing instance of type Temperature. ...."

This application simply converts from fahrenheit to celcius. I was learn swing, and through examples I found online... saw an indication that the gui form should be invoked as a runnable thread.

Once I modified the code to use runnable... I seem to have lost accessibility to the other classes in my main class "Temperature".

Any idea why?

Posts: 21817
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, please Use Code Tags in the future. I've added them for you, and your code looks a lot more readable.

The problem is the creation of instances of your two action listeners. You try to do this from a static method, but because the classes are not static inner classes you need an instance of Temperature to instantiate them. An easy fix in this case is to make those classes static, but in cases you can't you would need to create a Temperature object first:
Hug your destiny! And hug this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!