gpt4 book ai didi

java - 当我调用 @Listen onClick 时,ZK Framework 有线文本框返回 NullPointerException

转载 作者:行者123 更新时间:2023-11-30 05:52:34 26 4
gpt4 key购买 nike

我是 ZK Framework 的新手,正在使用简单的登录表单进行练习。当用户单击按钮时,我收集用户名/电子邮件和密码。

当我测试登录按钮时,发生 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>

Controller :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!");
}
}

现在,当我单击登录按钮时,会发生 NullPointerException,显示 this popup .

控制台日志

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() 函数抛出了异常。

最佳答案

您需要使用注释@Listen替换代码片段

@Listen("onClick = button#LoginButton")

@Listen("onClick = #LoginButton")

关于java - 当我调用 @Listen onClick 时,ZK Framework 有线文本框返回 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53648167/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com