Casting error on android device and not on simulator

Viewed 49

I see the following error from android tablet from log. Is there any issue in converting component to container in android?

1 Answers

As I wrote in the comments, I don't know why you have this casting error: because the class names in your log are obfuscated (by Proguard, that is used by default for Android), try to disable it temporarily to have a more readable log (I'm referring to the build hint android.enableProguard=false).

I have a lot of casting in my Codename One code. In general, for such cases, I use a code like the following:

        Container myCnt = new Container();
        myCnt.add(new Label("Test"));
        myCnt.add(new Container());

        for (Component cmp : myCnt.getChildrenAsList(true)) {
            if (cmp instanceof Container) {
                Container myChildCnt = (Container) cmp;
                // do what I need with myChildCnt
            } else {
                Log.p("cmp is not a Container, it is: " + cmp, Log.WARNING);
            }
        }

The only notable difference with your code is the log to investigate the casting error. In this case, the log is:

[EDT] 0:0:0,76 - cmp is not a Container, it is: Label[x=0 y=0 width=0 height=0 name=null, text = Test, gap = 2]

Remember to try Android and iPhone skins in the Simulator to see if there are differences.

Related