我创建了一个 Vaadin 项目,并使用 JSNI 编写脚本。但是当执行到 JSNI 脚本时,它会显示错误。
java.lang.UnsatisfiedLinkError: com.yty.cws.CiwsUI.jsniDemo()V
at com.yty.cws.CiwsUI.jsniDemo(Native Method) ~[classes/:na]
at com.yty.cws.CiwsUI.lambda$0(CwsUI.java:31) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_92]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_92]
以下是我的示例代码。
public class CiwsUI extends UI{
private static final long serialVersionUID = 5275145103992848572L;
VerticalLayout mainLayout=new VerticalLayout();
private TextField txtName=new TextField();
private Button btnJSNI=new Button("JSNI");
@Override
protected void init(VaadinRequest request) {
mainLayout.addComponents(txtName,btnJSNI);
setContent(mainLayout);
mainLayout.setComponentAlignment(txtName, Alignment.MIDDLE_CENTER);
mainLayout.setComponentAlignment(btnJSNI, Alignment.MIDDLE_CENTER);
btnJSNI.addClickListener(e->{
System.out.println("Clicked");
jsniDemo();
});
}
private native void jsniDemo()/*-{
$wnd.alert("Hai JSNI");
}-*/;
}
任何帮助是极大的赞赏。