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