I am very new to Codename One. As is 3 days new..
I have a Profile Container inside a Main Form. I have input text fields. When the user types in data and clicks the save button the profile data is saved to Storage. This works.
Now - when the user navigates out of the app and comes back to the profile page I want the profile data to be in the text fields if they have already entered something.
So I have a beforeMain method like this:
@Override
protected void beforeMain(Form f) {
// Get stored profile data here
Storage inappStore = Storage.getInstance();
Util.register("Profile", Profile.class);
if (inappStore.readObject("profile") != null) {
Profile userProfile = (Profile) inappStore.readObject("profile");
findFirstnameTextField().setText(userProfile.getFirstname());
}
}
I get this error:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.codename1.impl.javase.Executor$1.run(Executor.java:95)
at com.codename1.ui.Display.processSerialCalls(Display.java:1075)
at com.codename1.ui.Display.mainEDTLoop(Display.java:897)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
Caused by: java.lang.NullPointerException
at com.codename1.ui.util.UIBuilder.findByName(UIBuilder.java:578)
at generated.StateMachineBase.findFirstnameTextField(StateMachineBase.java:250)
at userclasses.StateMachine.beforeMain(StateMachine.java:51)
at generated.StateMachineBase.beforeShow(StateMachineBase.java:406)
at com.codename1.ui.util.UIBuilder.showForm(UIBuilder.java:2436)
at com.codename1.ui.util.UIBuilder.showForm(UIBuilder.java:2483)
at generated.StateMachineBase.startApp(StateMachineBase.java:62)
at generated.StateMachineBase.<init>(StateMachineBase.java:31)
at generated.StateMachineBase.<init>(StateMachineBase.java:110)
at userclasses.StateMachine.<init>(StateMachine.java:24)
at za.co.vine.communicatorFeature.CommunicatorApplication.start(CommunicatorApplication.java:35)
... 9 more
How can I initialize the field values?