Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query about Inner classes

 
Vinney Shanmugam
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post your code? It'll be easier for people to explain the cause
 
Vinney Shanmugam
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);

}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic