zk框架wired textbox返回nullpointerexception

kxe2p93d  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(568)

我是zk框架的新手,我正在用一个简单的登录表单来练习。当用户单击按钮时,我收集用户名/电子邮件和密码。
当我测试login按钮时,会发生nullpointerexception。我搞不清楚代码出了什么问题。你能帮助我吗?
让我们看看应用程序文件!

查看:login.zul

<?page title="Login" contentType="text/html;charset=UTF-8"?>
<zk>
    <window title="Login" border="normal" apply="zk_auth.controller.LoginController">
        <vlayout>
                Email: <textbox id="EmailBox" type="email" constraint="no empty" />
                Password: <textbox id="PasswordBox" type="password" constraint="no empty" />
        </vlayout>
            <button id="LoginButton" label="Login"/>
    </window>
</zk>

控制器:logincontroller.java

package zk_auth.controller;

/*Omitted imports for brevity.*/

public class LoginController extends SelectorComposer<Component>
{
    @Wire("LoginButton")
    private Button LoginButton;

    @Wire
    private Textbox EmailBox;

    @Wire
    private Textbox PasswordBox;

    @Listen("onClick = button#LoginButton")
    public void Login()
    {
        UserCredential User = new UserCredential(EmailBox.getValue(), PasswordBox.getValue());
        Authentication Authenticator = new Authentication();
        if(Authenticator.checkUserCredential(User))
            Messagebox.show("Authenticated!");
        else
            Messagebox.show("Access denied!");
    }
}

现在,当我单击login按钮时,出现一个nullpointerexception,显示这个弹出窗口。

控制台日志

dic 06, 2018 10:17:26 AM org.zkoss.util.resource.ResourceCache$Info isValid
INFORMAZIONI: Source is changed: /login.zul
dic 06, 2018 10:17:35 AM org.zkoss.zk.ui.impl.UiEngineImpl handleError
GRAVE: 
java.lang.NullPointerException
    at zk_auth.controller.LoginController.Login(LoginController.java:35)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.zkoss.zk.ui.select.Selectors$ComposerEventListener.onEvent(Selectors.java:686)
    at org.zkoss.zk.ui.AbstractComponent.onEvent(AbstractComponent.java:3162)
    at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:3132)
    at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:3074)
    at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:138)
    at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1846)
    at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1618)
    at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1321)
    at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:606)
    at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:482)
    at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:490)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:770)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

我真的不知道这段代码有什么问题。我只知道login()函数抛出了异常。

x6h2sr28

x6h2sr281#

您需要使用annotation@listen替换代码片段

@Listen("onClick = button#LoginButton")

@Listen("onClick = #LoginButton")

相关问题