Problem Compiling Inner Class

Can anyone tell me why the following won't compile?
Error : variable f might not have been initialized return f.getName();
     public void createNodes(File root, DefaultMutableTreeNode node)
          File [] files = root.listFiles();
          for(int counter = 0; counter < files.length; ++ counter)
               final File f = new File(files[counter].getPath())
                    public String toString()
                         return f.getName(); // Compiler error
                         //return ("ABC"); OKAY
               if(f.isDirectory())
                    DefaultMutableTreeNode dirNode = new DefaultMutableTreeNode(f.getName());
                    node.add(dirNode);
                    dirNode.setAllowsChildren(true); // HANDLE EMPTY DIRECTORIES
                    createNodes(f, dirNode);
               else
                    DefaultMutableTreeNode fileNode = new DefaultMutableTreeNode(f);
                    node.add(fileNode);
                    fileNode.setAllowsChildren(false);
     }

I had coded the thing like:
    for (int i = 0; i < files.length; i++) {
      final File f = new File(files[1].getPath()) {   // Yes that's a one in there
        public String toString() {
          return getName();
      System.out.println(f);
    }... Then passed into it a directory that contained a class named similar to an anonomous class name, and it just happened to be the 2nd file listed (files[1] that is) ... and therefore I got a whole bunch of that class name.class down the page instead of the entire contents of the directory ... and, oh well, threw me off ... like I said I think I need some sleep.
~Bill

Similar Messages

  • Problems with inner classes in JasminXT

    I hava problems with inner classes in JasminXT.
    I wrote:
    ;This is outer class
    .source Outer.j
    .class Outer
    .super SomeSuperClass
    .method public createrInnerClass()V
         .limit stack 10
         .limit locals 10
         ;create a Inner object
         new Outer$Inner
         dup
         invokenonvirtual Outer$Inner/<init>(LOuter;)V
         ;test function must print a Outer class name
         invokevirtual Outer$Inner/testFunction ()V
    .end method
    ;This is inner class
    .source Outer$Inner.j
    .class Outer$Inner
    .super java/lang/Object
    .field final this$0 LOuter;
    ;contructor
    .method pubilc <init>(LOuter;)V
         .limit stack 10
         .limit locals 10
         aload_0
         invokenonvirtual Object/<init>()V
         aload_0
         aload_1
         putfield Inner$Outer/this$0 LOuter;
         return
    .end method
    ;test
    .method public testFunction ()V
         .limit stack 10
         .limit locals 10
         ;get out object
         getstatic java/io/PrintStream/out  java/io/PrintStream;
         aload_0
         invokevirtual java/lang/Object/getClass()java/lang/Class;
         ;now in stack Outer$Inner class
         invokevirtual java/Class/getDeclaringClass()java/lang/Class;
         ;but now in stack null
         invokevirtual java/io/PrintStream/print (Ljava/lang/Object;)V
    .end methodI used dejasmin. Code was equal.
    What I have to do? Why getDeclatingClass () returns null, but in dejasmin code
    it returns Outer class?

    Outer$Inner naming convention is not used by JVM to get declaring class.
    You need to have proper InnerClasses attribute (refer to http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#79996)
    in the generated classes. Did you check using jclasslib or another class file viewer and verified that your .class files have proper InnerClasses attribute?

  • Compiling inner classes

    Hi,
    I have an applet with inner classes (the applet is contained in a single .java file). When I compile the applet, a number of *$*.class files are created for the inner classes. However, a friend of mine compiles the same .java file and he gets a single .class file. He can't see any files corresponding to the inner classes. My compiler is version 1.4.0, his is 1.4.2. Can you suggest how my friend can generate the *$*.class files corresponding to the inner classes?
    Thanks for your help.
    Miguel
    PS If the .jar file does not contain the *$*.class files, then appletviewer can't find the inner classes.

    Let me try again. My friend gets a single .class file.
    If he invokes the applet like this:
    <APPLet CODE="myapplet.class" WIDTH=100 HEIGHT=100>
    he has no problems at all.Because all the necessary files are there. Including the inner class files. Why he doesn't see them is another problem.
    However, if he puts his class file in myjar.jar and
    invokes the applet like this:
    <APPLet CODE="myapplet.class"
    ARCHIVE="myjar.jar"
    WIDTH=100 HEIGHT=100>
    then his inner classes are not found by appletviewer.Because he didn't put the inner class files in the jar. Why he didn't put them is another problem.
    There is abosolutely no other explanation I can see.

  • Cannot compile inner classes

    I have java source files that were created in another IDE. Some of these source files contain inner classes. When I attempt to compile them in JDev9i, the inner classes are not output.
    Has anyone experienced this problem in JDev?

    When I compile the source files containing inner classes, JDev does not output any Outerclass$xxx.class files, and the compiler complains that (for example):
    D:\path_to_source\source.java
    -Error(50,3): class VCMailer FileOpen$1 not found in class VCMailer.VCMailer
    There are no compile errors other than not being able to find the inner class files. FYI, the same file, unaltered, compiles without a problem in my other IDE. Building or making makes no difference, and the problem occurs whether it's the individual file, the project, or the workspace.
    I've done a test, creating a new class within the same project with a simple structure such as:
    package VCMailer;
    public class test {
    public test() {
    class innerTest{
    public innerTest(){
    This source file properly outputs an inner class. Strange.
    Matthew

  • JDev Compiler Error? - Compiling inner classes

    This maybe just an interpretation of the language standard, but the compiler behavaviour is different from previous versions of JDeveloper and other Java IDE's, with no explanation found.
    Using JDeveloper 9.02.829 the following error is received.
    Error(13,9): class test$abc not found in class test.test
    when compiling the following class
    package test;
    public class test
    class abc { }
    public test()
    public void t ()
    abc a = new abc();
    The solution is to ensure the package name and class name are different (case sensitive) iff the class contains an inner class
    Whilst this can be done it can pose a problem porting older code into this release of JDeveloper, whilst no problem exists with other IDE's or older versions of the JDevloper IDE.
    The question is this a bug or a feature?

    This is a bug that got fixed a while back. The bug is with
    the fact that the class and the package have the same name.
    The bug is definitely fixed in 9.0.3 Preview Release which
    is currently available on OTN. 9.0.3 Production should be
    available anyday now.
    Michel

  • Ant not always compiling inner classes

    hello,
    Every once in a while I get a troubled inner class. Ant doesn't always compile it (or maybe ant doesn't move it to the build directory). It's always the same inner classes... The compile will succeed, but when I run the program, it says that it's missing a class.
    ant clean fixes the problem.
    Any way I can stop this from happening?

    Ant doesn't always compile it (or maybe ant doesn't move it to the build directory).Did you check which?

  • Problem compiling Abstract class

    Hi
    I have writting an abstract class Sort.java and another class BubbleSort.java. I am having problems compiling BubbleSort.java class.
    The following is the error message
    BubbleSort.java:8: missing method body, or declare abstract
         public int doSorting(int[] array);
    ^
    BubbleSort.java:11: return outside method
              return num;
    ^
    The following is the code
    public abstract class Sort
    public abstract int doSorting(int[] array);
    }// End of class
    public class BubbleSort extends Sort
    private int num = 2;
    public int doSorting(int[] array);
    num = num + 2;
    return num;
    } // end of class

    Remove the semi-colon.
    public int doSorting(int[] array); // <------- there

  • Problems javadoc inner classes...

    Hi all,
    I have a problems documenting an inner class. I've implemented it this way:
    * In file TestClass.java I have an inner class "class MainClass" (this is the "upper" class of the file)
    * MainClass instantiates a TestClass (which in the file is declared as an inner class within MainClass: "public class TestClass").
    When I try to document it I get the following error message:
    "No public or protected classes found to document."
    What do I have to do? I'm using "Standard Doclet version 1.4.1" and why I have to use the inner class is a matter of saving a copy of the entire object, and I think this is the only solution to it, so what do I do?? Do I declare the "outer" class in a different way?
    Very pleased for all help!!
    Best regards,
    Anjelica

    * In file TestClass.java I have an inner class "class
    MainClass" (this is the "upper" class of the file)
    * MainClass instantiates a TestClass (which in the
    file is declared as an inner class within MainClass:
    "public class TestClass").So TestClass is an inner class of MainClass?? Then your file should be called MainClass.java.
    Try if that helps.

  • Problems with inner classes

    I ran into the following problems when I tried to read into an inner class:
    This is my .jdo file
    <?xml version="1.0"?>
    <jdo>
    <package name="com.globalrefund.jdo.mna">
    <class name="Parameter$Syspar" objectid-class="SysparId">
    <extension vendor-name="kodo" key="table" value="syspar"/>
    <extension vendor-name="kodo" key="lock-column" value="none"/>
    <extension vendor-name="kodo" key="class-column" value="none"/>
    <field name="landescode" primary-key="true">
    <extension vendor-name="kodo" key="data-column"
    value="landescode"/>
    </field>
    <field name="waehrungscode">
    <extension vendor-name="kodo" key="data-column"
    value="waehrungscode"/>
    </field>
    </class>
    </package>
    </jdo>
    1.) appidtool does not work for this inner class, I get this stack trace
    C:\users\Bernhard\jbProject\refundManual>appidtool
    src\com\globalrefund\jdo\mna\Parameter$Syspar.jdo
    Generating an application id for type "class
    com.globalrefund.jdo.mna.Parameter$Syspar"...
    Exception in thread "main" java.lang.NullPointerException
    at com.solarmetric.kodo.enhance.ApplicationIdTool.getFile(Unknown
    Source)
    at
    com.solarmetric.kodo.enhance.ApplicationIdTool.writeApplicationId(Unknown
    Source)
    at
    com.solarmetric.kodo.enhance.ApplicationIdTool.writeApplicationId(Unknown
    Source)
    at com.solarmetric.kodo.enhance.ApplicationIdTool.main(Unknown
    Source)
    2.) I tried to use a hand coded inner class as ID class, but id did not work
    (is this not possible ?)
    Exception in thread "main" java.lang.NoSuchMethodError:
    com.globalrefund.jdo.mna.Parameter$SysparId: method <init>()V not found
    at
    com.globalrefund.jdo.mna.Parameter$Syspar.jdoNewObjectIdInstance(Parameter.j
    ava)
    at
    javax.jdo.spi.JDOImplHelper.newObjectIdInstance(JDOImplHelper.java:166)
    at com.solarmetric.kodo.util.ObjectIds.fromPKValues(Unknown Source)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.JDBCStoreManager.createFromResultSet(
    Unknown Source)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.JDBCStoreManager$2.getResultObject(Un
    known Source)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.LazyResultList.instantiateRow(Unknown
    Source)
    at com.solarmetric.kodo.impl.jdbc.runtime.LazyResultList.get(Unknown
    Source)
    at java.util.AbstractList$Itr.next(AbstractList.java:416)
    at com.solarmetric.kodo.runtime.ResultListIterator.next(Unknown
    Source)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.ResultListFactory.createResultList(Un
    known Source)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.JDBCStoreManager.executeQuery(Unknown
    Source)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.JDBCQuery.executeQuery(Unknown
    Source)
    at com.solarmetric.kodo.query.QueryImpl.executeWithMap(Unknown
    Source)
    at com.solarmetric.kodo.query.QueryImpl.execute(Unknown Source)
    at
    com.solarmetric.kodo.query.QueryImpl$SynchronizedQuery.execute(Unknown
    Source)
    at com.globalrefund.jdo.mna.Parameter.<init>(Parameter.java:71)
    3.) It worked after I moved the ID class into a separate class
    Regards,
    Bernhard

    1.) appidtool does not work for this inner class, I get this stack traceThis is a bug. It will be corrected in the final release of 2.3, due out
    Real Soon Now. Thanks for catching this!
    2.) I tried to use a hand coded inner class as ID class, but id did not work
    (is this not possible ?)
    Exception in thread "main" java.lang.NoSuchMethodError:
    com.globalrefund.jdo.mna.Parameter$SysparId: method <init>()V not foundThis exception is saying that your application ID class does not have a
    no-args constructor. Make sure the id class is a static inner class;
    otherwise Java transparently adds a parent object parameter to each
    constructor, and so the application id class will violoate the JDO constraint
    of having a no-args constructor.

  • Problem creating inner class for JTable panel in a class for an application

    i want to create an inner class for a database application development.
    but there is occuring exceptions & errors.i want to retrieve data & enter data also from many tables in a database.i want an urgent help for this plz.

    http://forum.java.sun.com/thread.jsp?forum=57&thread=271752
    See this thread, please.

  • Problem compiling - Missing classes???

    I am trying to recompile my java classes using javac.exe and I get about 38 errors all saying "cannot resolve symbol"...I used to get more, but I figured it couldn't find some of the classes. I looked in the .java file and found the list of imports and found most of them, but I can not find the following that are being called:
    import java.applet.Applet;
    import java.applet.AppletContext;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    From what i have read, they should come with the Java 1.31 development kit, but I do not find them anywhere on my machine. I am new to Java and was asked to make some changes, so any help on this would really be appreciated.
    Thanks.

    These are all in the Java system jar. Do you have JRE or JVM installed?
    You could try reinstalling Java JVM.
    Regards,
    Tim

  • Why eclipse gives me warning if I access in inner class a parent  field ?

    I have a class
    class A{
    private Map fValues;
    A(){
    fValues= new HashMap();
    prrotected class B {
    B(){
    fValues.get("String");
    Above class is only for an example to expalin my problem.
    Inner class B wants to access fValues from class A .
    The eclipse gives me a warning
    Access to enclosing method fValues from the type A is emulated by a synthetic accessor method. Increasing its visibility will improve your performance
         I order to get rid of this warning I must make fValues public is this the only solution ?
    miro

    miro_connect wrote:
    I have a class
    class A{
    private Map fValues;
    A(){
    fValues= new HashMap();
    prrotected class B {
    B(){
    fValues.get("String");
    Above class is only for an example to expalin my problem.
    Inner class B wants to access fValues from class A .
    The eclipse gives me a warning
    Access to enclosing method fValues from the type A is emulated by a synthetic accessor method. Increasing its visibility will improve your performance
         I order to get rid of this warning I must make fValues public is this the only solution ?
    miroWhat happens if you remove the modifier? (That is uses default)

  • EJB fails to compile - static inner class problem

    I am using OC4J 9.0.4 and Sun JDK1.4.2 and EJBs fail to compile if they reference objects that contain static inner classes. However, they successfully compile under JDK1.4.1.
    For example, I have a class like below:
    public class ValueObject
    public static class Key
    private Key key;
    private String value;
    Any references to ValueObject.Key inside the EJB cause the EJB compiler to generate "ValueObject$Key" which is incorrect. JDK1.4.1 is more lenient than 1.4.2, and allows this error through.
    Is there a way around this problem other than reverting to JDK1.4.1?
    Regards,
    Andy

    The reason I don't want to move to JDK 1.4.1 is because of the memory leak in the StringBuffer.toString() method.
    Is there anywhere I can submit this as a bug?
    Regards,
    Andy

  • Problem with final variables and inner classes

    variables accessed by inner classes need to be final. Else it gives compilation error. Such clases work finw from prompt. But when I try to run such classes through webstart it gives me error/exception for those final variables being accessed from inner class.
    Is there any solution to this?
    Exception is:
    java.lang.ClassFormatError: com/icorbroker/fx/client/screens/batchorder/BatchOrderFrame$2 (Illegal Variable name " val$l_table")
         at java.lang.ClassLoader.defineClass0(Native Method)
         at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
         at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
         at com.sun.jnlp.JNLPClassLoader.defineClass(Unknown Source)
         at com.sun.jnlp.JNLPClassLoader.access$1(Unknown Source)
         at com.sun.jnlp.JNLPClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
         at com.icorbroker.fx.client.screens.batchorder.BatchOrderFrame.<init>(BatchOrderFrame.java:217)
         at com.icorbroker.fx.client.screens.batchorder.BatchOrderViewController.createView(BatchOrderViewController.java:150)
         at com.icorbroker.fx.client.screens.RealTimeViewController.initialize(RealTimeViewController.java:23)
         at com.icorbroker.fx.client.screens.batchorder.BatchOrderViewController.<init>(BatchOrderViewController.java:62)
         at com.icorbroker.fx.client.screens.displayelements.DisplayPanel$3.mousePressed(DisplayPanel.java:267)
         at java.awt.Component.processMouseEvent(Component.java:5131)
         at java.awt.Component.processEvent(Component.java:4931)
         at java.awt.Container.processEvent(Container.java:1566)
         at java.awt.Component.dispatchEventImpl(Component.java:3639)
         at java.awt.Container.dispatchEventImpl(Container.java:1623)
         at java.awt.Component.dispatchEvent(Component.java:3480)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3162)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
         at java.awt.Container.dispatchEventImpl(Container.java:1609)
         at java.awt.Window.dispatchEventImpl(Window.java:1590)
         at java.awt.Component.dispatchEvent(Component.java:3480)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

    I've also been having the same problem. The only work-around seems to be to slightly change the code, recompile & hope it works. See http://forum.java.sun.com/thread.jsp?forum=38&thread=372291

  • Compiler error when useing switch statements in an inner class

    I have defined several constants in a class and want to use this constans also in an inner class.
    All the constants are defined as private static final int.
    All works fine except when useing the switch statement in the inner class. I get the compiler error ""constant expression required". If I change the definition from private static final to protected static final it works, but why?
    What's the difference?
    Look at an example:
    public class Switchtest
       private static final int AA = 0;     
       protected static final int BB = 1;     
       private static int i = 0;
       public Switchtest()
          i = 0; // <- OK
          switch(i)
             case AA: break; //<- OK, funny no problem
             case BB: break; //<- OK
             default: break;
      private class InnerClass
          public InnerClass()
             i = 0; // <- OK: is accessible
             if (AA == i) // <- OK: AA is seen by the inner class; i  is also accessible
                i = AA + 1;
             switch(i)
                case AA: break; // <- STRANGE?! Fail: Constant expression required
                case BB: break; // <- OK
                default: break;
    }Thank's a lot for an explanation.

    Just a though:
    Maybe some subclass of Switchtest could decalare its own variable AA that is not final, but it can not declare its own BB because it is visible from the superclass. Therefore the compiler can not know for sure that AA is final.

Maybe you are looking for

  • InitialLdapContext can not be create with chinese principal name

    We use JNDI to search Domino 7 directory. It works well when the principal name contains only ASCII characters, but failed when chinese charaters are used in the principal name. This issue not occurrs when the same application is used to search Activ

  • Belle for Nokia 500 is available and there;s nothi...

    Belle update is available for my Nokia 500 and in m y country but Nokia suite says there's no updates available what should I do ? http://europe.nokia.com/find-products/nokia-belle-update/nokia-belle-update-availability

  • Error codes-keep getting booted offline

    I have the same issue When I start the Ps3 then Start the Game (GTA V) it immediately logs me out of PSN showing an Error Code (80028ED6). Anyone know anything about this ?

  • Cannot print to my kodak hero 9.1 wireless printer

    just bought a kodak hero 9.1 wireless printer and have no idea how to print off of my iphone five very computer challenged please help

  • Dependant LOV Filtering

    Hi, I have the following scenario: We have 3 model-driven LOVs: Region, Country & Operational Entity. All three are required fields implemented as Select One Choice components, as per requirement. But, we're getting errors when we attempt partial ref