JavaFX accessing Java Inner Classes

We have LOTS of common Java classes that look like this...
public class X {
    public class Y {
        public static final String Z = "ZzZZZzzZzzZzzZz";
}So in JAVA we can access them like this...
public String z = X.Y.Z;But in JavaFX I CAN'T do this...
var z : X.Y.Z;The compiler says +"non-static class com.myproject.X.Y cannot be referenced from a static context"+
Tell me it aint so, please :)

Galien, I doubt AndrewHughes can / want to change all the existing Java classes...
I tried to reproduce (I did) and found a workaround...
Java class (X.java):
public class X
    public static final String ZX = "ZzZZZzzZzzZzzZzXX";
    public class Y
        public static final String ZY = "ZzZZZzzZzzZzzZzYY";
    public static void main(String[] args)
      new A();
class A
  A()
    System.out.println(X.Y.ZY);
}OK, it works...
JavaFX code: var z = X.Y.Z;(and not var z: X.Y.Z; since Z isn't a type...) Error "+non-static class X.Y cannot be referenced from a static context+". Mmmm...
Trying var z = X.ZX; works, of course.
Looking at the generated class files, I thought of a workaround: var z = X$Y.ZY;Yay! it works! :-D

Similar Messages

  • Local variable can't be accessed from inner class ???????? Why ??????

    Plesae help, help, help. I have no idea what to do with this bug.........
    <code>
    for ( int i = 0; i <= 2; i++ ) {
    for ( int j = 0; j <= 2; j++ ) {
    grids[i][j] = new MyButton ();
    grids[i][j].setBorder(but);
    getContentPane().add(grids[i][j]);
    MyButton sub = grids[i][j];
    sub.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    if ( sub.getState() == 0 ) {
         sub = new MyButton( (Icon) new ImageIcon(imageFile));
         if ( imageFile.equals("cross.jpg") ) {
              sub.changeState(1);
         else {
              sub.changeState(2);
    </code>
    The compiler complains that "sub" is in the inner class, which is the ActionListener class, must be declared final. Please tell me what to do with it. I want to add an ActionListener to each MyButton Object in the array. Thanks ......

    OK, now I changed my code to this :
    for ( int i = 0; i <= 2; i++ ) {
      for ( int j = 0; j <= 2; j++ ) {
        grids[i][j] = new MyButton ();
        grids[i][j].setBorder(but);
        getContentPane().add(grids[i][j]);
        grids[i][j].addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            if ( grids[i][j].getState() == 0 ) {
               grids[i][j] = new MyButton( (Icon) new ImageIcon(imageFile));
              if ( imageFile.equals("cross.jpg") ) {
               grids[i][j].changeState(1);
              else {
              grids[i][j].changeState(2);
    [/cpde]
    Thanks for your advice !!!!!!
    Now the compiler says that i and j are local variables accessed from inner classes, needs to be declared final. How can I solve this then ???

  • Accessing the inner class written inside the method

    Hi all,
    Can any of you tell me how to access the inner class's method which is written inisde the outer class's method. THe code fragment is
    class Outer
    private static final int ID = 3;
    public String name;
    public void methodA( int nn )
    final int serialN = 11;
    class inner
    void showResult()
    System.out.println( "Rslt= "+ID );
    } // end class inner
    // new inner().showResult();
    } // end methodA
    class Sample
    public static void main(String a[])
    //access the showResult of Inner class??
    Thanks in advance.
    aah

    class Outer {
      private static final int ID = 3;
      public String name;
      public void methodA( int nn ) {
        final int serialN = 11;
        class inner {
          void showResult() {
            System.out.println( "Rslt= "+ID );
        } // end class inner
        new inner().showResult();
      } // end methodA
    class Sample {
      public static void main(String a[]) {
        new Outer().methodA(5);
    }

  • Access from inner class

    hi all,
    I have one frame with two panels inside, code likes the following:
    public class ShowChart extends JFrame{
    Container f = getContentPane();
    f.setLayout(new BorderLayout());
    JPanel chart=new drawChart();
    JPanel setting=new settingChart(chart);
    f.add(setting,java.awt.BorderLayout.WEST);
    f.add(chart);
    class drawChart extends JPanel(){
    setTableWidth(int w){...}
    class settingChart extends JPanel(){
    drawChart chart;
    pubic settingChart(drawChart c){
    chart=c;
    JTextField width = new JTextField("9",4);
    add(width);
    JButton change = new JButton("Change");
    change.addActionListener(new changeHandle(chart));
    add(change);
    change.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent event){
    int w = (int)Double.parseDouble(width.getText());
    chart.setTableWidth(w);
    Compilling error: local virable chart is accessed from within inner class, need to be declared as final. chart.setTabelWidth(w);
    how can i deal with this problem? (i know it will be ok if i messy all the viriables and method of settingChart into the ShowChart class, but it seems not a nice way...)
    thanks
    dejie

    Below is an example of an inner class field 'masking' the name of the outerclass field. So to access the outerclass you use OuterClass.this and then the field of that class...
    public class OuterClass {
      private int value = 1;
      class InnerClass {
        int value = 2;
        public InnerClass() {
          doStuff();
        void doStuff() {
          this.value++;
          OuterClass.this.value++;
    }Hope that helps...

  • 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)

  • Java inner classes

    G'day
    How does one - in CF - refer to an inner class (ClassFoo.Bar)
    of a given
    class (ClassFoo), when the constructor of ClassFoo takes an
    argument of
    type ClassFoo.Bar?
    For example the first, third,fourth and fifth constructors
    shown here:
    http://tinyurl.com/hfg9s
    (org.apache.lucene.document.Field).
    Any ideas?
    Adam

    >is the reason you can't use another "." because it is not
    a property of Field
    Thats my understanding, yes.
    > what does the $ represent
    Its part of the class name. It has to do with how java
    compiles the classes. It creates one file for the outer class and
    one for the inner class. The naming convention for inner class
    files is usually "OuterClassName$InnerClassName.class". So the
    class name passed to createObject() becomes
    bar = createObject("java", "OuterClassName$InnerClassName");

  • Java Inner classes within the Threading paradigm

    Hi all.
    Im familiar with static nested classes, method local classes, inner classes and anonymous classes.
    But what I am a little perplexed by, is when exactly to use inner classes or static nested classes? (forgetting anonymous classes and method local classes).
    I read this article (http://www.javaworld.com/javaworld/javaqa/2000-03/02-qa-innerclass.html) and the first point makes for a good argument, but why nest the class? Why not define it as an external class?
    Also you typically find nested classes within the Threading paradigm, but why?
    I typically would create a top level class (non nested) that would implement the Runnable interface, override run() and then
    use this class when constructing a new Thread.
    Any clarification would be greatly received.
    Thanks and Happy Friday.

    Boeing-737 wrote:
    I read this article (http://www.javaworld.com/javaworld/javaqa/2000-03/02-qa-innerclass.html) and the first point makes for a good argument, but why nest the class? Why not define it as an external class?
    I was going to provide some reasons, but when I read the article I found they were already there. Following the DRY principle I'm going to let the article speak for itself.
    Also you typically find nested classes within the Threading paradigm, but why?No, I don't. If that's where you typically find them then you haven't had a varied experience.
    I typically would create a top level class (non nested) that would implement the Runnable interface, override run() and then
    use this class when constructing a new Thread.So carry on doing that, if it works for you.

  • Local variable accessed within inner class

    Hey everybody,
    My program keeps telling me that it wont work because one of my methods is calling a local variable inside an inner class. Does anyone know what this means and how to fix it?
    Heres the code:
    public class SliderExample extends JPanel{
    int value=0;
    public SliderExample(int imw, int imh, Image img, BufferedImage buf, Graphics2D biCon){
    super(true);
    this.setLayout(new BorderLayout());
    JSlider slider= new JSlider(JSlider.HORIZONTAL,0,imw,25);
    slider.setMinorTickSpacing(10);
    slider.setMajorTickSpacing(100);
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);
    JButton redraw= new JButton("Scroll");
    redraw.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent ev){
    reDraw(slider,img,buf,biCon,imw,imh);
    add(slider,BorderLayout.CENTER);
    add(redraw,BorderLayout.AFTER_LINE_ENDS);
    public void reDraw(JSlider slid, Image im, BufferedImage bf, Graphics2D biC, int iw, int ih){
    value=slid.getValue();
    Graphics g= getGraphics();
    g.drawImage(im,value,0,iw,ih,this);
    g.drawImage(bf,value,0,iw,ih,this);
    biC.drawImage(bf,value,0,iw,ih,this);
    Any ideas???
    THanks,
    Rick

    Its getting them from another class thats calling the mothod to construct the slider bar with dedraw button. Thats a pretty big class but I will post the code where I called the method:
    public class Process extends JFrame implements MouseListener, MouseMotionListener{
    private int [][] points;
    private int [] lengths={0};
    private int [] bin;
    private String imstr;
    private String imsav;
    private int imgw=658;
    private int imgh=512;
    private int xArrayPos=0;
    private int yArrayPos=0;
    private int xpos=0;
    private int ypos=0;
    private int xprev;
    private int yprev;
    private int xadd;
    private int yadd;
    private String filstr;
    Image image;
    SimpleGUI gui;
    BufferedImage buffer;
    Graphics2D biContext;
    Graphics2D g2;
    BufferedImage last;
    Graphics2D lastContext;
    public Process(){
    JFrame slideFrame = new JFrame("Please slide to scroll image");
    slideFrame.setContentPane(new SliderExample(imgw, imgh,image,buffer,biContext));
    slideFrame.pack();
    slideFrame.setVisible(true);
    Thats what anything having to do with that function in the other class that calls the Slider Class.
    Do you know how I can fix this??
    Thanks,
    Rick

  • Java inner class access specifiers

    public class MyClass1 {
    public static void main(String argv[]){ }
    /*Modifier at XX */ class MyInner {}
    What modifiers would be legal at XX in the above code?
    1) public
    2) private
    3) static
    4) friend

    Iam a newbie to javaI don't care. I still assume you have a brain and expect you to use it.
    and iam struck with this
    question, iam getting a compile time error for any
    access specifiers mentioned as options, but the
    answers given by my superior are 1,2,3, are
    correct..Then you made a typo or whatever. Make sure you eliminate the problems that are not "illegal access modifier" errors.
    What good is knowing the reply to this if you can't even write an example?

  • How to call inner class method in one java file from another java file?

    hello guyz, i m tryin to access an inner class method defined in one class from another class... i m posting the code too wit error. plz help me out.
    // test1.java
    public class test1
         public test1()
              test t = new test();
         public class test
              test()
              public int geti()
                   int i=10;
                   return i;
    // test2.java
    class test2
         public static void main(String[] args)
              test1 t1 = new test1();
              System.out.println(t1.t.i);
    i m getting error as
    test2.java:7: cannot resolve symbol
    symbol : variable t
    location: class test1
              System.out.println(t1.t.geti());
    ^

    There are various ways to define and use nested classes. Here is a common pattern. The inner class is private but implements an interface visible to the client. The enclosing class provides a factory method to create instances of the inner class.
    interface I {
        void method();
    class Outer {
        private String name;
        public Outer(String name) {
            this.name = name;
        public I createInner() {
            return new Inner();
        private class Inner implements I {
            public void method() {
                System.out.format("Enclosing object's name is %s%n", name);
    public class Demo {
        public static void main(String[] args) {
            Outer outer = new Outer("Otto");
            I junior = outer.createInner();
            junior.method();
    }

  • Accessing inner Classes.. how?

    I'm reading the Java API and there is an Interface class named DocumentEvent that has an inner class named DocumentEvent.ElementChange..
    Since all is well with adding a DocumentListener (as per the API) for DocumentEvents, how is it possible to access the inner class' method? Do I need to implement another interface i.e. ElementChange and then write out all the methods?? What I really want is to use a method from DocumentEvent - getChange( Element elem) but this one relates to the inner class somehow.. can anyone answer this?
    Thanks so much!!!

    For example, in the caller
      A a = new A();
      (a.new B()).mm();for the method mm() in the inner class B of the class A.
    class A{
    class B{
      void mm(){
        System.out.println(Integer.MIN_VALUE);
    }

  • 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

  • Doubt in Inner class

    hi ,
    i have a doubt. How we can access a Inner class name by the outer class name using the Dot(.) operator .
    For example if we want to refer to the Inner class in some other class
    then we must say "OuterClass.InnerClass".
    This type of syntex is ment for the static methods in a class.
    Thus can we assume that Inner class is also a type of static member.
    If not then please explain the syntex.
    i am also not getting the way we create object of the Inner class object in some other class . (i mean to say the logic behind the syntex)
    i.e
    OuterClass Ob1=new OuterClass();
    OuterClass.InnerClass InnOb=Ob1.new InnerClass();
    Cna any one please help me out.
    Regards
    Arunabh

    Hi,
    Inner classes are used to create some functionality in terms of OO way. Like you want to have event handling which will work only for designated GUI classes, then we can make use of Innner class.
    Within a outer classes we do not require any reference of outer object BUT, if you want to access Inner class object outside the class then only we need a reference of Outer object so that we instantitate Inner class object.
    thanks,
    Sandeep

  • How to access var in outter class inside inner class

    I've problem with this, how to access var number1 and number2 at outter class inside inner class? what statement do i have to use to access it ? i tried with " int number1 = Kalkulator1.this.number1; " but there no value at class option var y when the program was running...
    import java.io.*;
    public class Kalkulator1{
    int number1,number2,x;
    /* The short way to create instance object for input console*/
    private static BufferedReader stdin =
    new BufferedReader( new InputStreamReader( System.in ) );
    public static void main(String[] args)throws IOException {
    System.out.println("---------------------------------------");
    System.out.println("Kalkulator Sayur by Cumi ");
    System.out.println("---------------------------------------");
    System.out.println("Tentukan jenis operasi bilangan [0-4] ");
    System.out.println(" 1. Penjumlahan ");
    System.out.println(" 2. Pengurangan ");
    System.out.println(" 3. Perkalian ");
    System.out.println(" 4. Pembagian ");
    System.out.println("---------------------------------------");
    System.out.print(" Masukan jenis operasi : ");
    String ops = stdin.readLine();
         int numberops = Integer.parseInt( ops );
    System.out.print("Masukan Bilangan ke-1 : ");
    String input1 = stdin.readLine();
    int number1 = Integer.parseInt( input1 );
    System.out.print("Masukan Bilangan ke-2 : ");
    String input2 = stdin.readLine();
    int number2 = Integer.parseInt( input2 );     
         Kalkulator1 op = new Kalkulator1();
    Kalkulator1.option b = op.new option();
         b.pilihan(numberops);
    System.out.println("Bilangan yang dimasukkan adalah = " + number1 +" dan "+ number2 );
    class option{
    int x,y;
         int number1 = Kalkulator1.this.number1;
         int number2 = Kalkulator1.this.number2;
    void pilihan(int x) {
    if (x == 1)
    {System.out.println("Operasi yang digunakan adalah Penjumlahan");
            int y = (number1+number2);
            System.out.println("Hasil dari operasi adalah = " + y);}
    else
    {if (x == 2) {System.out.println("Operasi yang digunakan adalah Pengurangan");
             int y = (number1-number2);
             System.out.println("Hasil dari operasi adalah = " + y);}
    else
    {if (x == 3) {System.out.println("Operasi yang digunakan adalah Perkalian");
             int y = (number1*number2);
             System.out.println("Hasil dari operasi adalah = " + y);}
    else
    {if (x == 4) {System.out.println("Operasi yang digunakan adalah Pembagian ");
             int y = (number1/number2);
             System.out.println("Hasil dari operasi adalah =" + y);}
    else {System.out.println( "Operasi yang digunakan adalah Pembagian ");
    }

    Delete the variables number1 and number2 from your inner class. Your inner class can access the variables in the outer class directly. Unless you need the inner and outer class variables to hold different values then you can give them different names.
    In future place code tags around your code to make it retain formatting. Highlight code and click code button.

  • Inner Classes Changing Access Rights Of Parent  Members

    I read that if you access a parent class's private memebers or methods from within an inner class, those members of methods will automatically and silently be converted to having package access. This seems dangerous and I'd like to know how I could design around it.
    Here is my current dilemma. I have an EventHandler class whose handleEvent() method changes with the object's state. I've implemented this using the Strategy Pattern, where the Strategy objects are inner classes of EventHandler. The problem is that these Strategy objects need access to certain private members and methods of their parent. There is no reason, however, to give package access to these members and methods. What can I do? Or does this suggest that I need a design change? Other than this issue, though, I'm quite happy with the design.
    Thanks for any thoughts,
    John

    When inner classes access private fields or methods, the compiler generates new package-private methods
    with names like "access$000":
    import java.lang.reflect.*;
    public class X {
        private void x() {}
        class Y {
            public void y() {
                x();
        public static void main(String[] args) {
            Method[] methods = X.class.getDeclaredMethods();
            for(int i=0; i<methods.length; ++i)
                System.out.println(methods.getName());
    So it's not correct that the access to fields or methods is changed, just that additional methods are added.
    Unless you're in the habit of writing method names that contain '$', I think it's unlikely that you'll directly call
    these new methods, and if you do, it should be easy to spot!

Maybe you are looking for

  • Mail as output for Delivery

    Hi     I want to send the delivery output as mail attachment. How can i acheive it?What are the configuration sterps to be done from SD point of veiw and other activities to acheive it? please suggest me. Thanks Arpitha

  • MAP - Label - Oracle Apex  4.0 -

    Hi everybody, I have some some questions about maps of Oracle Apex 4.0. I need to put many labels in my sql query, is it possible ? I know that the standard syntax is : select LINK, LABEL, VALUE .... But could we use two or three labels ? and how ? p

  • AS3: Tween from one MovieClip to Another

    Hi! As the title implies, I'm trying to use ActionScript 3 to tween from one movieclip to another based on an external event. I'm currently using two "Tween" objects to adjust alpha values. The first tweens-out the previous movieclip, and the second

  • AE program not running but service in task manager visible

    So, as title suggests, I dont' have my AE CS3 opened, but I can see it running in task manager. So when I want to run update it won't let me, because the service is running. Oh, if 'end process' would help, I wouldn't be posting this topic. Is there

  • Battery drains after update 4.3

    Have any had this problem. My phone keeps shutting down after 35% just started. Can someone help to resolve this? Thanks