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)

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...

  • Please give me the information when to use inner classes in applications

    HI,
    please give me when to use the innerclasses

    > HI,
    please give me when to use the innerclasses
    Use them when you want to create a class within another class.
    Now gimme all 'er Dukes!!!

  • 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

  • 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

  • Why we are making a variable as final in method inner class ?

    Why we are making the variable as final (method inner class) while we are accessing the method variable in inner class ?
    regards,
    namanc

    As far as I can tell, the only reason is to protect the programmer: when the inner class instance is constructed, it is given the then-current value of the variable. If the variable (or method parameter) later changes, the value held by the inner class would not. By making the variable final, the programmer doesn't have to worry about them staying in sync.
    Here's some code to ponder:
    public class InnerExample
        void printMe( final int x )
            Runnable runMe = new Runnable()
                public void run()
                    System.out.println(x);
            (new Thread(runMe)).start();
    }When compiled with the Sun JDK 1.4.2, you get this bytecode:
    void printMe(int);
      Code:
       0:   new     #2; //class InnerExample$1
       3:   dup
       4:   aload_0
       5:   iload_1
       6:   invokespecial   #3; //Method InnerExample$1."<init>":(LInnerExample;I)V
       9:   astore_2
       10:  new     #4; //class Thread
       13:  dup
       14:  aload_2
       15:  invokespecial   #5; //Method java/lang/Thread."<init>":(Ljava/lang/Runnable;)V
       18:  invokevirtual   #6; //Method java/lang/Thread.start:()V
       21:  returnAt line (byte) 5, it loads the passed value onto the stack; at line 6, it invokes the inner class constructor (which is created by the compiler). Nothing in this sequence of code would prevent use of a non-final variable.

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

  • FB70 why does system show warning message "enter true account assignment" ?

    FB70 why does system show warning message "enter a true account assignment object with revenues" ?
    i enter profit center but i still get warning message "enter a true account assignment object with revenues" 
    what should i do ?
    my  system have CO-PA .

    Dear,
    Please see that the profit center which you are entering in FB70 must have segment.
    still it gives warning message do worry enter it will post the transaction.
    bsrao

  • After moving my itunes library from my old WinXP computer to my new Win7 computer, itunes gives a warning that my content on my phone must be removed and re-synced. I want to merge changes/updates on my phone with my itunes library as normal, not erase it

    After moving my itunes library from my old WinXP computer to my new Win7 computer, itunes gives a warning that my content on my phone must be removed and re-synced. I want to merge changes/updates on my phone with my itunes library as normal, not erase it & replace it. My updates/changes will be lost.
    How do I merge content on my iPhone & content in iTunes together?

    Hopefully you still have the original library and can redo the migration...
    These are two possible approaches that will normally work to move an existing library to a new computer.
    Method 1
    Backup the library with this User Tip.
    Deauthorize the old computer if you no longer want to access protected content on it.
    Restore the backup to your new computer using the same tool used to back it up.
    Keep your backup up-to-date in future.
    Method 2
    Connect the two computers to the same network. Share your <User's Music> folder from the old computer and copy the entire iTunes library folder into the <User's Music> folder on the new one. Again, deauthorize the old computer if no longer required.
    Both methods should give the new computer a working clone of the library that was on the old one. As far as iTunes is concerned this is still the "home" library for your devices so you shouldn't have any issues with iTunes wanting to erase and reload.
    I'd recommend method 1 since it establishes an ongoing backup for your library.
    Note if you have iOS devices and haven't moved your contacts and calendar items across then you should create one dummy entry of each in your new profile and iTunes should  merge the existing data from the device.
    If your media folder has been split out from the main iTunes folder you may need to do some preparatory work to make it easier to move. See make a split library portable.
    Should you be in the unfortunate position where you are no longer able to access your original library or a backup then then see Recover your iTunes library from your iPod or iOS device for advice on how to set up your devices with a new library with the maximum preservation of data.
    tt2

  • HT3477 Why would a Guest network need an Access Control List?

    I have an Airport Extreme running software 7.6.4 and I have figured out today, to my dismay, that because I have an Access Control List active on my main network (with MAC addresses of my devices), the Guest Network feature, as implemented, becomes simply useless.
    Essentially any friend coming at my place, to whom I want to share my internet connection for a while (say, a couple of hours) with an easy password, either provides me with the MAC address of his device, or has no access at all. And if he has to give me the MAC, then I could just simply add him to the main network in the first place and, BTW, I need to give him also the (complicated) password of my main network.
    What is the purpose of a Guest Network then, if it is subject to the same access restrictions of the main one? I need to remove the access list on my main one, to offer quick and easy access to friends and family defeating the purpose of protecting my main network with MAC addresses and a separate guest network?
    I don't get it. This is a bug. It has to be. I see no logic in it, in the way it is implemented. Or it should have 2 separate access lists, for flexibility. But a *Guest* network, should be by definition open, or easy access (with password, sure, if necessary) - and in case it should have restricted access, it should be by time maybe, not by MAC address....!

    Why would a Guest Network need an Access Control List
    The short answer would be that it would not need an Access Control listing......if you used the default settings in Timed Access.
    Sorry, but I do not understand how you have constructed your Timed Access control list.
    Normally, you would use the default settings and leave the "main" (and "guest") networks set for Unlimited Access.....and then only list the devices that you want to limit separately, establishing "rules" and timeframes for each device that you want to control.
    When you do it the default way, a user would be able to connect to the Guest Network at any time, provided that he/she had the password for the guest network. No MAC Address needed at all.
    If you wanted to limit the time that the "guest" could connect to the guest network, you would have to set up a "rule" for the guest. I would not normally think of limiting the time that a guest could connect.....(unless the guest were one of the grandkids).
    It sounds to me as if you might have set the default network setting to No Access, and you have then set up each device with the times that they would be allowed to connect.
    If you did it this way, then the default No Access would also apply to the Guest Network....and any guest would have to then be set up by MAC Address with a rule set for the times that they were allowed to connect.
    Personally, I have changed the default rule for the "main" (and guest) networks from Unlimited Access to Everyday between 7:00 AM and 11:30 PM. So no one on either the main or guest network can connect before 7:00 AM or after 11:30 PM.
    Then, there are a few rules that I have for devices that connect to the guest network to further limit them to certain times each day. You could do this as well for devices that you want to control on the "main" network.

  • WARNING: Unable to access loaded classes

    Hi,
    Just installed OAS 10.1.3 on AIX. When I started the home OC4J instance, I got "WARNING: Unable to access loaded classes" in the OC4J~home~default_group~1 log file. Why this happened? Which classes unable to access?
    Thanks in advance.
    Richard

    Fixed as per Oracle Support (Note 376890.1 and Bug.5252013, not published yet)
    set the java system property in opmn.xml for home OC4J instance
    -Dclass.transfer=delegate

  • I have a an iMac 27" and am trying to import some videos of a friends wedding into iMovie however one of the movies won't import. It doesn't say why or give any error message or codes. All of the other movies on the card download with out a problem.

    I have an iMac 27" and am trying to import some videos of a friends wedding into iMovie however one of the movies won't import. It doesn't say why or give any error message or codes.
    All of the other movies on the card download with out a problem. The movie in question is not 'corrupt' as you can watch it in iMovie direct from the SD card but as soon as you try to import it, it  just says 'error'. iIve tried moving the file to an external drive ( and other variations on this theme) then importing but have had no luck.
    Can anyone please help me.

    The mystery remains....
    Thanks for the pointers. The file type is .mts (a proprietry sony one).
    I have now found some video converter software (Wondershare and iSkysoft) at a cost. Either will convert this file for me into .mp4. This I can then import into iMovie without any problems. I've checked this on the trial versions and it worked well but without paying am left with a giant watermark in the video
    The mystery (which I still havent solved) is why did 20 other .mts files import fine and then this one not?
    If you could point me in the direction of some free .mts converter software that would be the cherry on the cake.
    Thanks

  • Have a nice day. I can't open the books linked to the Adobe ID. Always the overallocation says. But some of the books I downloaded two times. Still, it gives a warning in the form of more installations.

    Have a nice day. I can't open the books linked to the Adobe ID. Always the overallocation says. But some of the books I downloaded two times. Still, it gives a warning in the form of more installations.

    I think you should ask in the Digital Editions forum, Adobe Digital Editions

Maybe you are looking for

  • Ipod Mini no longer recognized - can't reload itunes 6

    We downloaded Itunes 6 this past Saturday but last night the system no longer recognizes that the Ipod Mini is there and says that the program for communication with the ipod is missing. When I try to download Itunes 6 to reinstall, the automatic dow

  • Footer not staying at bottom of page

    http://www.mrjindustrial.com.au/index_newicons.html The footer is not sticking to the bottom of the page when viewed on a reasonable-sized monitor. There's a large space beneath it. I have not been able to work out exactly why this is happening, and

  • Material Documents for Unplanned Services?

    Dear All I have created a service entry sheet for services against a PO. In the PO, provision was maintained for unplanned service (maintaining some amount in limits.) Now, while creating service entry sheet, it has been observed that material docume

  • Oracle 11G - set id password to not expire

    Hello, I've created an Oracle 11G database. The default on passwords is to expire every 180 days. I need to create an account that batch processes can use (for application code) which will not expire. How do I set a password on a user id to not expir

  • SharePoint Designer: throwing error while open my sharepoint web applicaiton

    When i try to open web application in sharepoint designer. I can't able to open it throw error like this An Error occured accessing your Microsoft sharepoint foundation site files. Authors - if authoring against a web server, please contact the webma