我试图在vaadin中将浮点值转换为int值,但当我在textfield中插入某项内容并单击该按钮(错误消息出现在按钮的上下文菜单中)时,会得到此错误:
com.vaadin.server.ServerRpcManager$RpcInvocationException:无法调用com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:170) at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:118) at com.vaadin.server.communication.ServerRpcHandler.handleBurst(ServerRpcHandler.java:207)的com.vaadin.shared.ui.button.ButtonServerRpc中的方法
诸若此类。
这是我的Java代码:
package com.eduwallchart.schulung2;
import javax.servlet.annotation.WebServlet;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
@Theme("mytheme")
@SuppressWarnings("serial")
public class MyVaadinUI extends UI {
@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = MyVaadinUI.class, widgetset = "com.eduwallchart.schulung2.AppWidgetSet")
public static class Servlet extends VaadinServlet {
}
@Override
protected void init(VaadinRequest request) {
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);
Button button = new Button("Convert Float to Int");
final TextField textfield = new TextField("Int-Wert:");
Label label = new Label("0.0");
button.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
float floatValue;
String intValue;
floatValue = (Float) textfield.getData();
intValue = String.valueOf(floatValue);
textfield.setCaption(intValue);
}
});
layout.addComponent(textfield);
layout.addComponent(button);
}
}
我正在运行NetBeans 7.4中的代码,并使用本地TomCat服务器(在IDE中)。
发布于 2014-07-12 03:43:11
好吧,我自己找到答案了。它必须是:
public void buttonClick(ClickEvent event) {
floatValue = Float.parseFloat(textfield.getValue());
intValue = Math.round(floatValue);
stringValue = String.valueOf(intValue);
textfield.setCaption(stringValue);
}
https://stackoverflow.com/questions/20529143
复制相似问题