This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Query about Inner classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Query about Inner classes" Watch "Query about Inner classes" New topic
Author

Query about Inner classes

Vinney Shanmugam
Ranch Hand

Joined: Aug 27, 2008
Posts: 104
I have an inner classB inside classA.ClassA public and class B is private.With java 1.4.2 the code is compiled without error and with java 1.5 it is not compiling. In class B there is a string variable c which is used in some method which is not the method of class B.
The error is c is defined in a inaccessible class or interface(only with java 1.5)

Can anyone clear what's wrong in this?
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Can you post your code? It'll be easier for people to explain the cause


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Vinney Shanmugam
Ranch Hand

Joined: Aug 27, 2008
Posts: 104
Originally posted by Martijn Verburg:
Can you post your code? It'll be easier for people to explain the cause


here is the piece of code....


This is in a seprate file, say ObtainChannel.java,

public class ObtainChannel
{
private static final int MAX_IOR_STRING_LENGTH = 4000;
private static final int MAX_EVENT_CHANNELS = 50;
static EventChannelInfo[] ChannelList = new EventChannelInfo[MAX_EVENT_CHANNELS];
static int NumChannels = 0;

private static class EventChannelInfo
{
String fullChannelName; //This is giving the error : it's not accesible
String channelName; // "
NamingContext context;// "

EventChannelInfo(String fullChannelName, String channelName, NamingContext context)
{
this.fullChannelName = fullChannelName;
this.channelName = channelName;
this.context = context;
}
}

This is another file, say ChanAdmin.java ( this file is using fullChannelName,channelName,context varaible decalred in above class) and throws the following error,

ChanAdmin.java:202: fullChannelName in ObtainChannel.EventChannelInfo is defined
in an inaccessible class or interface
info.channelChoice.add(ObtainChannel.ChannelList[i].fullChannelName)
;


public class ChanAdmin extends Frame
{

private void startAdmin(int xPosition, int yPosition)
{
EventChannelHolder eventChannelHolder = new EventChannelHolder();

// Display a dialog to query operator about which event channel
// to administer
IdentifyChannelDialog info = new IdentifyChannelDialog(this, true);
info.setLocation(50, 50);
for (int i=0; i < ObtainChannel.NumChannels; i++)
{
info.channelChoice.add(ObtainChannel.ChannelList[i].fullChannelName);// It's giving error
}
if (ObtainChannel.NumChannels == 0) info.channelChoice.setEnabled(false);
info.setVisible(true);
int choice = info.channelChoice.getSelectedIndex();
info.dispose();

// Get the event channel either from the naming service or from a file
// based object reference.
if (info.fileNameField.getText().length() == 0)
{
if (ObtainChannel.NumChannels == 0)
// Naming service not available and no event channel IOR provided
Runtime.getRuntime().exit(-1);

// Use naming service to get event channel
if (!ObtainChannel.FromNamingService(
ObtainChannel.ChannelList[choice].context, // It's giving error
ObtainChannel.ChannelList[choice].channelName, // It's giving error
eventChannelHolder))
Runtime.getRuntime().exit(-1);
}
else
{ // Get Event Channel from IOR stored in a file
if (!ObtainChannel.FromIORFile(orb, eventChannelHolder,
info.fileNameField.getText()))
Runtime.getRuntime().exit(-1);
}


eventChannelObj = eventChannelHolder.value;

// Start a thread for updating statistics periodically
statUpdate = new StatUpdate(this);
statUpdate.start();

// Display the administration window
setLocation(xPosition, yPosition);
setVisible(true);

}
 
GeeCON Prague 2014
 
subject: Query about Inner classes