an enclosing instance that contains com.company.properties.PropertySheetCon

Hi All,

an enclosing instance that contains com.company.properties.PropertySheetContainer.PageNameInfo is required

I am getting the above error when I try to compile

com.company.properties.PropertySheetContainer.PageNameInfo pageNameInfo = new com.company.properties.PropertySheetContainer.PageNameInfo(this, tab.getName());

Please advise

Message was edited by:

Java_help

[415 byte] By [Java_helpa] at [2007-11-27 3:46:05]
# 1

Hi,

I assume you have a class PropertySheetContainer with an inner class PageName. For inner classes, you have two types:

- non-static inner classes

- static inner classes

An instance of a non-static inner class is always linked to an instance of the surrounding class. This enables you to access fields and methods of the surrounding class. However to establish this linkage, you have to instantiate such a non-static inner class within a non-static method of the surrounding class.

A static inner class does not have this linkage. Therefore the restriction on creation of an instance of such a class does not exist.

If you do not require the linkage, add the "static" keyword to the definition of your inner class ("static class PageName"). However if you want to access non-static fields and methods of PropertySheetContainer, then you should instantiate the PageName from a method of PropertySheetContainer.

If you want to instantiate such a class from outside, then you need an object of the surrounding class, e.g.

PropertySheetContainer container = new PropertySheetContainer();

PropertySheetContainer.PageName name = container.new PageName();

Here you explicitely link the new PageName to an instance of the container.

Martin

martin@worka at 2007-7-12 8:49:51 > top of Java-index,Java Essentials,Java Programming...