access to static public nested classes

J

J.R. Heisey

In the Java compiler 1.4 this works but I get a compile time error
listed below in the Javac 1.4.2. Is this a Java compiler bug? Do I
need to break a part my classes?

// Contain.java
package i;

public class Contain {
public Contain() { }


static public class InnerClass {
int i;
public InnerClass() {
i = 0;
}

public int getValue( ) { return 1; }
}

}

// UClass.java
package i;

import i.Contain;
import i.Contain$InnerClass;

public class UClass {

public UClass() { }

// I can't get main() to run using javac 1.4 at this moment
// and I'm too tire to pursue my configuration problem.
public static void main(String[] args) {
Contain c = new Contain();
i.Contain$InnerClass ii = new i.Contain$InnerClass();
System.out.println( " value = " + ii.getValue() );
}
}


The error
///////////////////////////////////////////////////////////
[w:\test]javac Contain.java UClass.java
UClass.java:4: cannot resolve symbol
symbol : class Contain$InnerClass
location: package i
perchance you meant 'Contain.InnerClass'
import i.Contain$InnerClass;
^
UClass.java:12: cannot resolve symbol
symbol : class Contain$InnerClass
location: package i
perchance you meant 'Contain.InnerClass'
i.Contain$InnerClass ii = new i.Contain$InnerClass();
^
UClass.java:12: cannot resolve symbol
symbol : class Contain$InnerClass
location: package i
perchance you meant 'Contain.InnerClass'
i.Contain$InnerClass ii = new i.Contain$InnerClass();
^
3 errors
 
K

KC Wong

The error
///////////////////////////////////////////////////////////
[w:\test]javac Contain.java UClass.java
UClass.java:4: cannot resolve symbol
symbol : class Contain$InnerClass
location: package i
perchance you meant 'Contain.InnerClass'
import i.Contain$InnerClass;
^
<snip more compile errors>

Oh man, why don't you listen to your compiler? Use "." instead of "$" !


Say you have a nested class:

package test.nested;
public class Outer {
public class Inner {
}
}

In the other class calling them,

package test.caller;

import test.nested.Outer;

public class Caller {
public Outer outerClass;
public Outer.Inner innerClass;
}
 
J

J.R. Heisey

Yeah that's right, but here is the whole story.

The class is the implementation for a taglib. Instead
creating several files for each tag I used nested classes
to provide some class scoping. I.E. a StoreInventory class
would have a StoreInventory.Tag inner class. I originally
did this with the command line compiler and the standalone
version of Tomcat. Now I'm trying to put this code into the
latest version of NetBeans with JC 1.4.2 and I'm having
trouble. It might have something to do with how NetBeans
defines classpaths.

I can get the java files to compile in NetBeans but the JSPs
are currently my problem. In my JSP file ...
<%@page import="com.jr.webstore.ShopInventory.Tag"%>
.... some JSP code ...
<store:inventory id="merchandise" scope="application" />

// this line generates the error whether or not I explicitly import
the com.jr.webstore.ShopInventory.Tag class.

ShopCart.jsp [54:0] Unable to load class com.jr.webstore.ShopInventory.Tag
Errors compiling ShopCart. [jsp]

This has something to do with the way NetBeans uses the
tld files to reference the class for the tag and where
it expects to find the class.

Part of my problem is I'm not fimiliar with NetBeans and I
am trying to incorporate preexisting files into a NetBeans
project. I'm finding that to correct some errors I've had to
generate a duplicate file my file with NetBeans the copy
my code into the duplicate. Simply adding the file to the project
isn't quite the same thing. At this point I've mucked
with the whole project definition so much it is probably
a bastardized project.

Anyone have a JSP based application with their own tag libraries
that I can use as a reference? I'm about ready to give up on
NetBeans and use the command line tools but I really would like
a source level debugger.

Thanks

KC Wong said:
The error
///////////////////////////////////////////////////////////
[w:\test]javac Contain.java UClass.java
UClass.java:4: cannot resolve symbol
symbol : class Contain$InnerClass
location: package i
perchance you meant 'Contain.InnerClass'
import i.Contain$InnerClass;
^
<snip more compile errors>

Oh man, why don't you listen to your compiler? Use "." instead of "$" !


Say you have a nested class:

package test.nested;
public class Outer {
public class Inner {
}
}

In the other class calling them,

package test.caller;

import test.nested.Outer;

public class Caller {
public Outer outerClass;
public Outer.Inner innerClass;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,160
Latest member
CollinStri
Top