3

I'm using the last version of LWUIT (1.5). I designed my forms in resource editor and then generate the code to netbeans. The problem is if i want to access any object except the form i got this error:

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)

This is my code:

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());
    }

also i tried this:

fltAmount += Float.parseFloat(findTxtAmount(root).getText());
aditya
  • 302
  • 3
  • 15
Ali
  • 1,451
  • 1
  • 15
  • 19

1 Answers1

1

Is the text amount field a component that is within the current form or a different form. If it is in a different form then this won't work.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • I just have one form and inside i have a Tab with 4 tabs, each of them has an embedded container and this field is in my first tab. – Ali Nov 13 '12 at 06:10
  • If you have an embedded container you must give a component from within the embedded container to find the text field since it won't be listed within the form. You can get the tab and get the specific embedded container from there, pass that to the find function. – Shai Almog Nov 13 '12 at 11:32