Listeners and Variable errors
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Listeners and Variable errors

  1. #1
    Join Date
    Jun 2008
    Posts
    32

    Listeners and Variable errors

    Getting an error in the code below relating to the line with selectedFileHolder. The code has to do with adding a PropertyChangeListener for a swing worker which will copy a converted File to selectedFileHolder when it detects the conversion job is done.


    Code:
    import java.util.Vector;
    
    class X
    {
    
    public void actionPerformed(ActionEvent e)
    {
    File selectedFileHolder;
    
    
    task.addPropertyChangeListener(
    
        new PropertyChangeListener() {
    
            @Override
                public void propertyChange(PropertyChangeEvent evt) {
    
               if (task.getState() == StateValue.DONE) {
    
                       try {
                       selectedFileHolder = task.get();//error line
                       } catch (InterruptedException exp) {
                       exp.printStackTrace();
                    } catch (ExecutionException exp) {
                       exp.printStackTrace();
                       }
               }
                }
        }
    
    }
    
    }
    it says

    Cannot refer to a non-final variable selectedFileHolder inside an inner class defined in a different method.

    When I made selectedFileHolder final it switched to

    The final local variable selectedFileHolder cannot be assigned, since it is defined in an enclosing type

    For some reason another error just popped up near the top at

    import java.util.Vector;


    Internal compiler error java.lang.IllegalArgumentException: info cannot be null at org.eclipse.jdt.internal.compiler.codegen.StackMapFrame.addStackItem(StackMapFrame.java:81)


    Maybe this is a deprecated import?

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: Listeners and Variable errors

    The easiest solution is to make selectedFileHolder a private instance variable.
    I'm not entirely convinced by your design - selectedFileHolder will be changed asynchronously so why is it a local variable anyway - what are you trying to achieve?

    Internal compiler error java.lang.IllegalArgumentException: info cannot be null at org.eclipse.jdt.internal.compiler.codegen.StackMapFrame.addStackItem(StackMapFrame.java:81)
    This has nothing to do with your code, it looks like the eclipse compiler has fallen over.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Jun 2008
    Posts
    32

    Re: Listeners and Variable errors

    Quote Originally Posted by keang View Post
    The easiest solution is to make selectedFileHolder a private instance variable.
    I'm not entirely convinced by your design - selectedFileHolder will be changed asynchronously so why is it a local variable anyway - what are you trying to achieve?

    This has nothing to do with your code, it looks like the eclipse compiler has fallen over.

    Aite, I moved the variables to the top and put them to private and the errors disappeared...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center