Java cannot reference non final variables
•
Java
Continue to give me the following code:
package com.gwt.churchweb.churchweblogin.client; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.FlexTable; import com.google.gwt.user.client.ui.Text@R_79_2419@; import com.google.gwt.user.client.ui.HasHorizontalAlignment; import com.google.gwt.user.client.ui.Check@R_79_2419@; import com.google.gwt.user.client.ui.Button; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.user.client.Window; public class Login extends Composite { public Login() { VerticalPanel verticalPanel = new VerticalPanel(); initWidget(verticalPanel); verticalPanel.setSize("329px","186px"); Label lblNewLabel = new Label("Sign into your account"); lblNewLabel.setStyleName("gwt-Login-SigninLabel"); verticalPanel.add(lblNewLabel); FlexTable flexTable = new FlexTable(); verticalPanel.add(flexTable); flexTable.setWidth("308px"); Label lblNewLabel_1 = new Label("Username:"); lblNewLabel_1.setStyleName("gwt-Label-Login"); flexTable.setWidget(0,lblNewLabel_1); lblNewLabel_1.setWidth("72px"); Text@R_79_2419@ text@R_79_2419@Username = new Text@R_79_2419@(); text@R_79_2419@Username.setStyleName("gwt-LoginText@R_79_2419@"); flexTable.setWidget(0,1,text@R_79_2419@Username); text@R_79_2419@Username.setWidth("204px"); Label lblNewLabel_2 = new Label("Password:"); lblNewLabel_2.setStyleName("gwt-Label-Login"); flexTable.setWidget(1,lblNewLabel_2); lblNewLabel_2.setWidth("66px"); Text@R_79_2419@ text@R_79_2419@Password = new Text@R_79_2419@(); text@R_79_2419@Password.setStyleName("gwt-LoginText@R_79_2419@"); flexTable.setWidget(1,text@R_79_2419@Password); text@R_79_2419@Password.setWidth("204px"); flexTable.getCellFormatter().setHorizontalAlignment(0,HasHorizontalAlignment.ALIGN_LEFT); flexTable.getCellFormatter().setHorizontalAlignment(1,HasHorizontalAlignment.ALIGN_LEFT); Check@R_79_2419@ chckbxRememberMeOn = new Check@R_79_2419@("Remember me on this computer"); chckbxRememberMeOn.setStyleName("gwt-Check@R_79_2419@-Login"); flexTable.setWidget(2,chckbxRememberMeOn); Button btnSignIn = new Button("Sign In"); btnSignIn.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { if (text@R_79_2419@Username.getText().length() == 0 || text@R_79_2419@Password.getText().length() == 0) { Window.alert("Username or password is empty."); } } }); btnSignIn.setStyleName("gwt-Login-SigninButton"); flexTable.setWidget(3,btnSignIn); } }
Solution
final Text@R_79_2419@ text@R_79_2419@Username = new Text@R_79_2419@();
final Text@R_79_2419@ text@R_79_2419@Username = new Text@R_79_2419@();
and
final Text@R_79_2419@ text@R_79_2419@Password = new Text@R_79_2419@();
It should be solved
Java requires that variables in internal classes be referenced as final variables (for concurrency management reasons, I think)
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码