gpt4 book ai didi

nullpointerexception - 无法访问除窗体之外的任何对象,NullPointerException 错误

转载 作者:行者123 更新时间:2023-12-02 03:54:26 27 4
gpt4 key购买 nike

我使用的是最新版本的 LWUIT (1.5)。我在资源编辑器中设计了我的表单,然后将代码生成到 netbeans。问题是如果我想访问除表单之外的任何对象,我会收到此错误:

java.lang.NullPointerException at userclasses.StateMachine.onCtnCalculation_BtnAddAction(StateMachine.java:38) at generated.StateMachineBase.handleComponentAction(StateMachineBase.java:712) at com.sun.lwuit.util.UIBuilder$FormListener.actionPerformed(UIBuilder.java:2231) at com.sun.lwuit.util.EventDispatcher.fireActionSync(EventDispatcher.java:312) at com.sun.lwuit.util.EventDispatcher.fireActionEvent(EventDispatcher.java:257) at com.sun.lwuit.Button.fireActionEvent(Button.java:364) at com.sun.lwuit.Button.released(Button.java:395) at com.sun.lwuit.Button.released(Button.java:384) at com.sun.lwuit.Button.keyReleased(Button.java:413) at com.sun.lwuit.Form.keyReleased(+64) at com.sun.lwuit.Display.handleEvent(Display.java:1533) at com.sun.lwuit.Display.edtLoopImpl(Display.java:826) at com.sun.lwuit.Display.mainEDTLoop(Display.java:776) at com.sun.lwuit.RunnableWrapper.run(RunnableWrapper.java:119)

这是我的代码:

protected void onCtnCalculation_BtnAddAction(Component c, ActionEvent event) {
// If the resource file changes the names of components this call will break notifying you that you should fix the code
super.onCtnCalculation_BtnAddAction(c, event);
Form root = Display.getInstance().getCurrent();
TextField txtAmount = findTxtAmount(root);
fltAmount += Float.parseFloat(txtAmount.getText());
}

我也试过这个:

fltAmount += Float.parseFloat(findTxtAmount(root).getText());

最佳答案

文本金额字段是当前表单中的组件还是其他表单中的组件。如果它采用不同的形式,那么这将不起作用。

关于nullpointerexception - 无法访问除窗体之外的任何对象,NullPointerException 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13305211/

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