openGeeksLab / codenameone

Automatically exported from code.google.com/p/codenameone
0 stars 0 forks source link

showForm() with backCommand causes arrayIndexOutOfBounds error #363

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Please clearly state whether the issue relates to a device/the simulator or
the tools.

Happens in real device and simulator both.

If related to a device be sure to specify exactly which device with as much
details as possible.

Tested on iPhone 4, OS 6.0

What steps will reproduce the problem?
1. Add a button on the form which acts as a transition to a different form.
2. When that button is pressed, you want to have a back transition and go back 
to other form.
3. Press the button once and use the following code in the action event:

    protected void onTxnHistory_HomeAction(Component c, ActionEvent event) {
        // TODO Auto-generated method stub
        super.onTxnHistory_HomeAction(c, event);
        // Show home form
        showForm("MainUI", (c.getComponentForm() == null) ? null : c.getComponentForm().getBackCommand());
    }

What is the expected output? What do you see instead?

However when the button is pressed, once, we get the following error:

java.lang.ArrayIndexOutOfBoundsException: 1 > 0
    at java.util.Vector.insertElementAt(Vector.java:551)
    at com.codename1.ui.Container.insertComponentAt(Container.java:407)
    at com.codename1.ui.Container.addComponent(Container.java:426)
    at com.codename1.ui.MenuBar.addCommand(MenuBar.java:992)
    at com.codename1.ui.Form.addCommand(Form.java:2051)
    at com.codename1.ui.util.UIBuilder.initBackForm(UIBuilder.java:1861)
    at com.codename1.ui.util.UIBuilder.showForm(UIBuilder.java:2060)
    at com.codename1.ui.util.UIBuilder.showForm(UIBuilder.java:2160)
    at com.nvsoft.s2pay.fsm.StateMachine.onTxnHistory_HomeAction(StateMachine.java:2244)
    at com.nvsoft.s2pay.fsm.generated.StateMachineBase.handleComponentAction(StateMachineBase.java:4280)
    at com.codename1.ui.util.UIBuilder$FormListener.actionPerformed(UIBuilder.java:2339)
    at com.codename1.ui.util.EventDispatcher.fireActionSync(EventDispatcher.java:366)
    at com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:311)
    at com.codename1.ui.Button.fireActionEvent(Button.java:364)
    at com.codename1.ui.Button.released(Button.java:395)
    at com.codename1.ui.Button.pointerReleased(Button.java:483)
    at com.codename1.ui.Form.pointerReleased(Form.java:1991)
    at com.codename1.ui.Component.pointerReleased(Component.java:2163)
    at com.codename1.ui.Display.handleEvent(Display.java:1641)
    at com.codename1.ui.Display.edtLoopImpl(Display.java:906)
    at com.codename1.ui.Display.mainEDTLoop(Display.java:853)
    at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:119)
    at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:171)

After this when you press the button again, it works.

What version of the product are you using? On what operating system?

Latest version of codename1.

Please provide any additional information below.

Also please note if you press the hardware back button/Esc key in simulator 
when on this form then it is transitioning to the previous form without error 
but when you press the above button on the form it causes the error.

Original issue reported on code.google.com by nir...@nvsoft.com on 13 Oct 2012 at 12:21

GoogleCodeExporter commented 9 years ago
On some further testing on simulator, I am getting the following error when 
using the Esc key to go back to previous form. This might be related to the 
above error:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at com.codename1.impl.javase.JavaSEPort$8.actionPerformed(JavaSEPort.java:1244)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.AbstractButton.doClick(AbstractButton.java:389)
    at com.apple.laf.ScreenMenuItem.actionPerformed(ScreenMenuItem.java:95)
    at java.awt.MenuItem.processActionEvent(MenuItem.java:650)
    at java.awt.MenuItem.processEvent(MenuItem.java:609)
    at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:343)
    at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:331)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
    at java.awt.EventQueue.access$400(EventQueue.java:82)
    at java.awt.EventQueue$2.run(EventQueue.java:663)
    at java.awt.EventQueue$2.run(EventQueue.java:661)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue$3.run(EventQueue.java:677)
    at java.awt.EventQueue$3.run(EventQueue.java:675)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:674)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
An exception occurred during transition paint this might be valid in case of a 
resize in the middle of a transition
An exception occurred during transition paint this might be valid in case of a 
resize in the middle of a transition
java.lang.ArrayIndexOutOfBoundsException: 1 > 0
    at java.util.Vector.insertElementAt(Vector.java:551)
    at com.codename1.ui.Container.insertComponentAt(Container.java:407)
    at com.codename1.ui.Container.addComponent(Container.java:426)
    at com.codename1.ui.MenuBar.addCommand(MenuBar.java:992)
    at com.codename1.ui.Form.addCommand(Form.java:2051)
    at com.codename1.ui.util.UIBuilder.initBackForm(UIBuilder.java:1861)
    at com.codename1.ui.util.UIBuilder.showForm(UIBuilder.java:2060)
    at com.codename1.ui.util.UIBuilder.showContainerImpl(UIBuilder.java:2018)
    at com.codename1.ui.util.UIBuilder.showContainer(UIBuilder.java:1902)
    at com.codename1.ui.util.UIBuilder$FormListener.actionPerformed(UIBuilder.java:2406)
    at com.codename1.ui.util.EventDispatcher.fireActionSync(EventDispatcher.java:366)
    at com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:311)
    at com.codename1.ui.Form.actionCommandImpl(Form.java:1156)
    at com.codename1.ui.Form.actionCommandImpl(Form.java:1131)
    at com.codename1.ui.MenuBar.keyReleased(MenuBar.java:1274)
    at com.codename1.ui.Form.keyReleased(Form.java:1658)
    at com.codename1.ui.Display.handleEvent(Display.java:1625)
    at com.codename1.ui.Display.edtLoopImpl(Display.java:906)
    at com.codename1.ui.Display.mainEDTLoop(Display.java:853)
    at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:119)
    at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:171)

Original comment by nir...@nvsoft.com on 13 Oct 2012 at 1:20

GoogleCodeExporter commented 9 years ago
While I can fix this exception I don't think this will produce the behavior you 
want.
Since you want to navigate back you need to invoke the back method and not 
invoke show.
When you invoke showForm you automatically add a new form to the navigation 
stack which means that the UIBuilder is trying to insert a back command into 
your home screen (probably not what you want).

Original comment by shai.almog on 13 Oct 2012 at 5:49

GoogleCodeExporter commented 9 years ago
Hi Shai,

Actually on the press of this button, I want to go back to the Home
screen. And when that home form is shown, I want to have the back
transition effect to that form. Also I thought, when we show the
homeForm, the navigation stack will be cleared.

What do you suggest, the best way to achieve the following:

Starting from a home form, I have a couple of forms which the user
goes through to a final form. Once in the final form, when user
presses (hardware back or Home button), he should go back to the home
form. The in-between forms would have the normal back navigation,
however once we reach the final screen, there is no need to go back to
the previous forms, but directly to the home screen.

Original comment by nir...@nvsoft.com on 15 Oct 2012 at 6:41

GoogleCodeExporter commented 9 years ago
I see what you mean, I have a fix for this. Will be up in the next update. 

Original comment by shai.almog on 15 Oct 2012 at 12:04

GoogleCodeExporter commented 9 years ago
Hi Shai,

FYI: this also happens even if you do not call showForm() explicitly, but just 
use the hardware back button. Here's the stack trace for it:

java.lang.ArrayIndexOutOfBoundsException: 1 > 0
    at java.util.Vector.insertElementAt(Vector.java:551)
    at com.codename1.ui.Container.insertComponentAt(Container.java:407)
    at com.codename1.ui.Container.addComponent(Container.java:426)
    at com.codename1.ui.MenuBar.addCommand(MenuBar.java:992)
    at com.codename1.ui.Form.addCommand(Form.java:2051)
    at com.codename1.ui.util.UIBuilder.initBackForm(UIBuilder.java:1861)
    at com.codename1.ui.util.UIBuilder.showForm(UIBuilder.java:2060)
    at com.codename1.ui.util.UIBuilder.showContainerImpl(UIBuilder.java:2018)
    at com.codename1.ui.util.UIBuilder.showContainer(UIBuilder.java:1902)
    at com.codename1.ui.util.UIBuilder$FormListener.actionPerformed(UIBuilder.java:2406)
    at com.codename1.ui.util.EventDispatcher.fireActionSync(EventDispatcher.java:366)
    at com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:311)
    at com.codename1.ui.Form.actionCommandImpl(Form.java:1156)
    at com.codename1.ui.Form.actionCommandImpl(Form.java:1131)
    at com.codename1.ui.MenuBar.keyReleased(MenuBar.java:1274)
    at com.codename1.ui.Form.keyReleased(Form.java:1658)
    at com.codename1.ui.Display.handleEvent(Display.java:1625)
    at com.codename1.ui.Display.edtLoopImpl(Display.java:906)
    at com.codename1.ui.Display.mainEDTLoop(Display.java:853)
    at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:119)
    at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:171)

Original comment by nir...@nvsoft.com on 16 Oct 2012 at 5:22