Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] hi.getContentPane().getComponentAt(i).remove() fails #2913

Closed
jsfan3 opened this issue Sep 7, 2019 · 1 comment

Comments

@jsfan3
Copy link
Contributor

jsfan3 commented Sep 7, 2019

Test case:

Form hi = new Form("Hi World", BoxLayout.y());
        for (int i=0; i<100; i++) {
            hi.add(new Label("Test"));
        }
        hi.show();
        for (int i=0; i<99; i++) {
            Log.p(hi.getContentPane().getComponentCount() + "");
            hi.getContentPane().getComponentAt(i).remove();
        }
        hi.revalidate();
        Log.p(hi.getContentPane().getComponentCount() + "");

In my opinion this code is correct and it doesn't do anything of special: it adds 100 Labels and then it removes the first 99 Labels. But it fails, this is the log:

[EDT] 0:0:0,77 - 100
[EDT] 0:0:0,78 - 99
[EDT] 0:0:0,78 - 98
[EDT] 0:0:0,78 - 97
[EDT] 0:0:0,78 - 96
[EDT] 0:0:0,78 - 95
[EDT] 0:0:0,78 - 94
[EDT] 0:0:0,78 - 93
[EDT] 0:0:0,79 - 92
[EDT] 0:0:0,79 - 91
[EDT] 0:0:0,79 - 90
[EDT] 0:0:0,79 - 89
[EDT] 0:0:0,79 - 88
[EDT] 0:0:0,79 - 87
[EDT] 0:0:0,79 - 86
[EDT] 0:0:0,79 - 85
[EDT] 0:0:0,79 - 84
[EDT] 0:0:0,79 - 83
[EDT] 0:0:0,80 - 82
[EDT] 0:0:0,80 - 81
[EDT] 0:0:0,80 - 80
[EDT] 0:0:0,80 - 79
[EDT] 0:0:0,80 - 78
[EDT] 0:0:0,80 - 77
[EDT] 0:0:0,80 - 76
[EDT] 0:0:0,80 - 75
[EDT] 0:0:0,80 - 74
[EDT] 0:0:0,81 - 73
[EDT] 0:0:0,81 - 72
[EDT] 0:0:0,81 - 71
[EDT] 0:0:0,81 - 70
[EDT] 0:0:0,81 - 69
[EDT] 0:0:0,81 - 68
[EDT] 0:0:0,81 - 67
[EDT] 0:0:0,81 - 66
[EDT] 0:0:0,81 - 65
java.lang.IndexOutOfBoundsException: Index: 50, Size: 50
[EDT] 0:0:0,81 - 64
[EDT] 0:0:0,81 - 63
[EDT] 0:0:0,81 - 62
[EDT] 0:0:0,81 - 61
[EDT] 0:0:0,81 - 60
[EDT] 0:0:0,82 - 59
[EDT] 0:0:0,82 - 58
[EDT] 0:0:0,82 - 57
[EDT] 0:0:0,82 - 56
[EDT] 0:0:0,82 - 55
[EDT] 0:0:0,82 - 54
[EDT] 0:0:0,82 - 53
[EDT] 0:0:0,82 - 52
[EDT] 0:0:0,82 - 51
[EDT] 0:0:0,82 - 50
	at java.util.ArrayList.rangeCheck(ArrayList.java:657)
	at java.util.ArrayList.get(ArrayList.java:433)
	at com.codename1.ui.Container.getComponentAt(Container.java:1749)
	at net.informaticalibera.tests.Count.start(Count.java:61)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.codename1.impl.javase.Executor$3$1.run(Executor.java:256)
	at com.codename1.ui.Display.processSerialCalls(Display.java:1298)
	at com.codename1.ui.Display.mainEDTLoop(Display.java:1093)
	at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
	at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)

Tested on the Simulator.

@jsfan3

This comment has been minimized.

Copy link
Contributor Author

jsfan3 commented Sep 7, 2019

I'm sorry, my mistake, my code is wrong, there is no bug. The correct code is:

Form hi = new Form("Hi World", BoxLayout.y());
        for (int i=0; i<100; i++) {
            hi.add(new Label("Test"));
        }
        hi.show();
        for (int i=99; i>0; i--) {
            Log.p(hi.getContentPane().getComponentCount() + "");
            hi.getContentPane().getComponentAt(i).remove();
        }
        hi.revalidate();
        Log.p(hi.getContentPane().getComponentCount() + "");

or

Form hi = new Form("Hi World", BoxLayout.y());
        for (int i=0; i<100; i++) {
            hi.add(new Label("Test"));
        }
        hi.show();
        for (int i=0; i<99; i++) {
            Log.p(hi.getContentPane().getComponentCount() + "");
            hi.getContentPane().getComponentAt(0).remove();
        }
        hi.revalidate();
        Log.p(hi.getContentPane().getComponentCount() + "");

both of them work correctly.

@jsfan3 jsfan3 closed this Sep 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.