Research Log of Web Science Students

Computer Science is not simply programming

Posts Tagged ‘final

Finally Speaking

with 2 comments

I have this certain code and I can’t seem to get the variable i plugged in to the MouseUpHandler. It seems that I cannot refer to a non-final variable inside an inner class.

for(int i = 0; i < activityCount; i++) {
activities.add(new VerticalPanel());
activities.get(i).add(new Label("Learning Activity #" + (i + 1)));

objectList.add(new VerticalPanel());

Button addLink = new Button("Add");
addLink.addMouseUpHandler(new MouseUpHandler() {
public void onMouseUp(MouseUpEvent event) {
addObject(i); // I CAN'T DO THIS!

And I haven’t figured out how to code-style-display the code above unlike what partner does.


Written by Paolo Sy

November 29, 2009 at 1:54 am

Posted in Hardwire

Tagged with , ,