无法访问除表单之外的任何对象,NullPointerException错误

时间:2012-11-09 09:22:56

标签: nullpointerexception lwuit

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

  

java.lang.NullPointerException at   userclasses.StateMachine.onCtnCalculation_BtnAddAction(StateMachine.java:38)   在   generated.StateMachineBase.handleComponentAction(StateMachineBase.java:712)   在   com.sun.lwuit.util.UIBuilder $ FormListener.actionPerformed(UIBuilder.java:2231)   在   com.sun.lwuit.util.EventDispatcher.fireActionSync(EventDispatcher.java:312)   在   com.sun.lwuit.util.EventDispatcher.fireActionEvent(EventDispatcher.java:257)   在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());

1 个答案:

答案 0 :(得分:1)

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