cn1-native-controls Implementation crash in UpdateStyle

41 views
Skip to first unread message

B3G B3G

unread,
Apr 2, 2020, 9:04:00 PM4/2/20
to CodenameOne Discussions

I am trying to test NTextField in Xcode, i have already Implement a cn1-native-controls in my project and implementation has ben well done.  but, unfortunately the app crash while i trying to instantiate "NTextField". I extracted the generated source code & run it on Xcode this is the error log trace I got: (screen shot)


my code is :


         NTextField tf1 = new NTextField(TextField.PASSWORD);

            tf1.getAllStyles().setFont(Font.createTrueTypeFont(Font.NATIVE_MAIN_LIGHT, 15f));

            System.out.println("Finished setting font");

            tf1.getAllStyles().setFgColor(0x003300);

            tf1.getAllStyles().setBgTransparency(255);

            tf1.getAllStyles().setBgColor(0xcccccc);

            tf1.getAllStyles().setAlignment(CENTER);


Do you have any fix for this issue?



If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans
Desktop OS : MacOS
Simulator : Iphone XR
Device
Screen Shot 2020-04-03 at 01.43.46.png

Steve Hannah

unread,
Apr 2, 2020, 9:43:21 PM4/2/20
to codenameone...@googlegroups.com
Can you post the stack trace from Xcode?

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/556ed685-57a2-434d-864c-6a89a6e83ac2%40googlegroups.com.
--
Steve Hannah
Software Developer
Codename One

B3G B3G

unread,
Apr 2, 2020, 9:59:29 PM4/2/20
to codenameone...@googlegroups.com
nothin traced in xcode, i think the following screenshot will help you 


Screen Shot 2020-04-03 at 01.43.46.png

Steve Hannah

unread,
Apr 2, 2020, 10:00:26 PM4/2/20
to codenameone...@googlegroups.com
Xcode will show the stack in its left panel.

Message has been deleted

Steve Hannah

unread,
Apr 3, 2020, 10:17:57 AM4/3/20
to codenameone...@googlegroups.com
The stack will be shown in the left panel, like
image.png



On Thu, Apr 2, 2020 at 8:12 PM B3G B3G <soufia...@gmail.com> wrote:

the stack trace :


/com_codename1_nui_NTextFieldNativeImpl.m:279:23: error: use of undeclared identifier 'font'

            float s = font.pointSize / scale;

                      ^

/com_codename1_nui_NTextFieldNativeImpl.m:280:25: error: use of undeclared identifier 'font'; did you mean 'jfont'?

            utf.font = [font fontWithSize:s];

                        ^~~~

                        jfont

/com_codename1_nui_NTextFieldNativeImpl.m:256:17: note: 'jfont' declared here

    JAVA_OBJECT jfont = com_codename1_nui_NTextField_getNativeFont___int_R_java_lang_Object(CN1_THREAD_GET_STATE_PASS_ARG idx);

                ^

/com_codename1_nui_NTextFieldNativeImpl.m:280:25: warning: receiver type 'JAVA_OBJECT' (aka 'struct JavaObjectPrototype *') is not 'id' or interface pointer, consider casting it to 'id' [-Wreceiver-expr]

            utf.font = [font fontWithSize:s];

                        ^~~~

/com_codename1_nui_NTextFieldNativeImpl.m:282:24: error: use of undeclared identifier 'font'; did you mean 'jfont'?

            utf.font = font;

                       ^~~~

                       jfont

/com_codename1_nui_NTextFieldNativeImpl.m:256:17: note: 'jfont' declared here

    JAVA_OBJECT jfont = com_codename1_nui_NTextField_getNativeFont___int_R_java_lang_Object(CN1_THREAD_GET_STATE_PASS_ARG idx);

                ^

/com_codename1_nui_NTextFieldNativeImpl.m:282:22: warning: incompatible pointer types assigning to 'UIFont * _Nullable' from 'const JAVA_OBJECT' (aka 'struct JavaObjectPrototype *const') [-Wincompatible-pointer-types]

            utf.font = font;

                     ^ ~~~~

/com_codename1_nui_NTextFieldNativeImpl.m:294:1: warning: conflicting return type in implementation of 'stopEditing': 'BOOL' (aka 'bool') vs 'void' [-Wmismatched-return-types]


--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.

B3G B3G

unread,
Apr 3, 2020, 10:29:04 AM4/3/20
to codenameone...@googlegroups.com
Screen Shot 2020-04-03 at 15.27.39.png

Steve Hannah

unread,
Apr 3, 2020, 12:07:36 PM4/3/20
to codenameone...@googlegroups.com
I've made a small change to guard against this scenario (where the style doesn't have a font defined).  You can get the updated cn1lib here https://github.com/shannah/cn1-native-controls/blob/master/bin/cn1-native-controls.cn1lib

Or wait until it is updated in Codename One settings and update there - should be within a few days.

I've posted my test case here (which works fine on iOS). 

Steve

B3G B3G

unread,
Apr 3, 2020, 10:19:45 PM4/3/20
to codenameone...@googlegroups.com
thank's Steve.

the application does not crash now, but the problem in the style that I defined is not taken into consideration, and the size(width) of TextField is very small as you see in screenshot

Screen Shot 2020-04-04 at 03.18.14.png

Steve Hannah

unread,
Apr 3, 2020, 10:21:28 PM4/3/20
to codenameone...@googlegroups.com

Try setting the font to one of the native fonts or other ttf font

B3G B3G

unread,
Apr 3, 2020, 10:46:53 PM4/3/20
to codenameone...@googlegroups.com

I followed your example, by putting a native font.

My code :

       TableLayout t = new TableLayout(1, 2);
        final Container cntPin = new Container(t);
        final NTextField tfCodePin = new NTextField(TextField.PASSWORD);
        tfCodePin.getAllStyles().setFont(Font.createTrueTypeFont(Font.NATIVE_MAIN_LIGHT, 3f));
       
        tfCodePin.getAllStyles().setFgColor(0x003300);
        tfCodePin.getAllStyles().setBgTransparency(255);
        tfCodePin.getAllStyles().setBgColor(0xcccccc);

        cntPin.add(t.createConstraint().widthPercentage(50), lblPinCode);
        cntPin.add(t.createConstraint().widthPercentage(50), tfCodePin);

B3G B3G

unread,
Apr 4, 2020, 8:47:02 PM4/4/20
to codenameone...@googlegroups.com
Do you have any fix for  my issue?

B3G B3G

unread,
Apr 7, 2020, 10:47:30 PM4/7/20
to codenameone...@googlegroups.com
Hi, 
I still have the same problem even if I took your example :
the code i tested is this one, and i also tried to setting the font to one of the native fonts or other ttf fon

My code :

       TableLayout t = new TableLayout(1, 2);
        final Container cntPin = new Container(t);
        final NTextField tfCodePin = new NTextField(TextField.PASSWORD);
        tfCodePin.getAllStyles().setFont(Font.createTrueTypeFont(Font.NATIVE_MAIN_LIGHT, 3f));
       
        tfCodePin.getAllStyles().setFgColor(0x003300);
        tfCodePin.getAllStyles().setBgTransparency(255);
        tfCodePin.getAllStyles().setBgColor(0xcccccc);

        cntPin.add(t.createConstraint().widthPercentage(50), lblPinCode);
        cntPin.add(t.createConstraint().widthPercentage(50), tfCodePin);


Screen Shot 2020-04-04 at 03.18.14.png

Steve Hannah

unread,
Apr 9, 2020, 8:25:04 AM4/9/20
to codenameone...@googlegroups.com
I copied and pasted your code into a sample app, and I don't get the same thing:

image.png

private void showTestForm2() {
        Form f = new Form("Test Form", new BorderLayout());

        TableLayout t = new TableLayout(1, 2);
        final Container cntPin = new Container(t);
        final NTextField tfCodePin = new NTextField(TextField.PASSWORD);
        tfCodePin.getAllStyles().setFont(Font.createTrueTypeFont(Font.NATIVE_MAIN_LIGHT, 3f));
       
        tfCodePin.getAllStyles().setFgColor(0x003300);
        tfCodePin.getAllStyles().setBgTransparency(255);
        tfCodePin.getAllStyles().setBgColor(0xcccccc);

        cntPin.add(t.createConstraint().widthPercentage(50), new Label("Pin Code"));
        cntPin.add(t.createConstraint().widthPercentage(50), tfCodePin);
        f.add(CENTER, cntPin);
        f.show();
    }





Reply all
Reply to author
Forward
0 new messages