Yusufcihan Dynamic Components Extension: Attempt to invoke virtual method 'int org.json.JSONArray.length()' on a null object reference

Trying to create using dynamic component extension.
But getting error with the schema.
I have validated the schema but still gives error

{
    "name": "Cus",
    "metadata-version": 1,
    "author": "cus",
    "platforms": [
        "ai2.appinventor.mit.edu"
    ],
    "extensions": {},
    "keys": [
        "id",
        "Que",
        "Image",
        "Option",
        "Intro",
        "EImage",
        "fulltext",
        "keyconcepts",
        "KImage",
        "keyconcepts2",
        "RBook"
    ],
    "components": [
        {
            "id": "Q{id}",
            "type": "Label",
            "properties": {
                "FontSize": 16,
                "FontTypeface": "AvertaDemoPE-Regular.otf",
                "Width": -1090,
                "Text": "{Que}",
                "TextColor": -526345
            },
            "components": []
        },
        {
            "id": "H1{id}",
            "type": "HorizontalArrangement",
            "properties": {},
            "components": [
                {
                    "id": "I{id}",
                    "type": "Image",
                    "properties": {
                        "Width": -1089,
                        "Picture": "{Image}"
                    },
                    "components": []
                }
            ]
        },
        {
            "id": "H2{id}",
            "type": "HorizontalArrangement",
            "properties": {
                "AlignVertical": 2,
                "Width": -1089
            },
            "components": [
                {
                    "id": "H3{id}",
                    "type": "HorizontalArrangement",
                    "properties": {
                        "AlignHorizontal": 3,
                        "AlignVertical": 2
                    },
                    "components": [
                        {
                            "id": "L{id}",
                            "type": "Label",
                            "properties": {
                                "FontSize": 16.5,
                                "FontTypeface": "AvertaStd-Semibold.ttf",
                                "Text": "A",
                                "TextColor": -526345
                            },
                            "components": []
                        }
                    ]
                },
                {
                    "id": "O{id}",
                    "type": "Label",
                    "properties": {
                        "FontSize": 16,
                        "FontTypeface": "AvertaDemoPE-Regular.otf",
                        "Width": -1090,
                        "Text": "{Option}",
                        "TextColor": -526345
                    },
                    "components": []
                }
            ]
        },
        {
            "id": "EA{id}",
            "type": "VerticalArrangement",
            "properties": {
                "AlignHorizontal": 3,
                "Width": -1089
            },
            "components": [
                {
                    "id": "L1{id}",
                    "type": "Label",
                    "properties": {
                        "FontSize": 18,
                        "FontTypeface": "AvertaStd-Semibold.ttf",
                        "HTMLFormat": true,
                        "Width": -2,
                        "Text": "Explanation :",
                        "TextColor": -3777197
                    },
                    "components": []
                },
                {
                    "id": "intro{id}",
                    "type": "Label",
                    "properties": {
                        "FontSize": 16,
                        "FontTypeface": "AvertaDemoPE-Regular.otf",
                        "HTMLFormat": true,
                        "Width": -2,
                        "Text": "{Intro}",
                        "TextColor": -3355444
                    },
                    "components": []
                },
                {
                    "id": "H4{id}",
                    "type": "HorizontalArrangement",
                    "properties": {
                        "AlignHorizontal": 3,
                        "AlignVertical": 2,
                        "Width": -2
                    },
                    "components": [
                        {
                            "id": "EI{id}",
                            "type": "Image",
                            "properties": {
                                "Width": -2,
                                "Picture": "{EImage}"
                            },
                            "components": []
                        }
                    ]
                },
                {
                    "id": "full{id}",
                    "type": "Label",
                    "properties": {
                        "FontSize": 15,
                        "FontTypeface": "AvertaDemoPE-Regular.otf",
                        "HTMLFormat": true,
                        "Width": -2,
                        "Text": "{fulltext}",
                        "TextColor": -3355444
                    },
                    "components": []
                },
                {
                    "id": "L2{id}",
                    "type": "Label",
                    "properties": {
                        "FontSize": 18,
                        "FontTypeface": "AvertaStd-Semibold.ttf",
                        "HTMLFormat": true,
                        "Width": -2,
                        "Text": "Key Points :",
                        "TextColor": -3777197
                    },
                    "components": []
                },
                {
                    "id": "key{id}",
                    "type": "Label",
                    "properties": {
                        "FontSize": 16,
                        "FontTypeface": "AvertaDemoPE-Regular.otf",
                        "HTMLFormat": true,
                        "Width": -2,
                        "Text": "{keyconcepts}",
                        "TextColor": -3355444
                    },
                    "components": []
                },
                {
                    "id": "H5{id}",
                    "type": "HorizontalArrangement",
                    "properties": {
                        "Width": -2
                    },
                    "components": [
                        {
                            "id": "KC{id}",
                            "type": "Image",
                            "properties": {
                                "Width": -2,
                                "Picture": "{KImage}",
                                "ScalePictureToFit": true
                            },
                            "components": []
                        }
                    ]
                },
                {
                    "id": "key2{id}",
                    "type": "Label",
                    "properties": {
                        "FontSize": 16,
                        "FontTypeface": "AvertaDemoPE-Regular.otf",
                        "HTMLFormat": true,
                        "Width": -2,
                        "Text": "{keyconcepts2}",
                        "TextColor": -3355444
                    },
                    "components": []
                },
                {
                    "id": "book{id}",
                    "type": "Label",
                    "properties": {
                        "FontItalic": true,
                        "FontSize": 15,
                        "FontTypeface": "AvertaDemoPE-Regular.otf",
                        "HTMLFormat": true,
                        "Width": -2,
                        "Text": "{RBook}",
                        "TextColor": -7829368
                    },
                    "components": []
                }
            ]
        }
    ]
}

Which extension ? I am guessing yusufcihan ?

yes.
Do you see any error in the schema ??

Let us see if @yusufcihan can help ?

Usually, the best way to generate a schema is to actually build the components that make the layout, then get the schema from that.

this extension is working differently with CompCreator, maybe you want to try CompCreator.

Thats how i did it .
but i dont know whats causing the error.
can anyone try and let me know is it the error same with you

You would need to provide an example aia project that repeats this behaviour.

1 Like

Schema_Error.aia (35.5 KB)

You didn't provide the original blocks the schema was created from.

To be honest I do not use this extension so am perhaps not the best person to advise.

You may need to debug, in which case start with your first component, test, then the next component, test, and so on.

Where is the custom font referred to in the schema ?

What I do know is that schemas work with CompCreator, as suggested above.

This error should indicate that "components" or "keys" is not a list, but your schema the types are not wrong, so there is nothing wrong with your schema from what I can see. Perhaps you are using an older version? Nevermind, I just saw the AIA, and it is the currently released version (2.2.2), that's strange. I will investigate what's going wrong.

Update: Looks like the template getting "malformed" somehow when replacing the keys, I guess I need to come up with a safer solution that doesn't affect the whole template string.

I made some changes to parsing of the schema, it should be more reliable right now. Here's the updated version:

com.yusufcihan.DynamicComponents.aix (31.7 KB)

Also, after fixing the schema parsing, I was still getting an error and I couldn't figure it out, and I tried to fix this error believed it was caused by the extension itself, but after examining the logs for a while, I saw this message, and it turns out that the root cause was:

Font asset not found /storage/emulated/0/Android/data/edu.mit.appinventor.aicompanion3/files/assets/AvertaDemoPE-Regular.otf

So the schema won't work until you remove the specified custom font or add these fonts to the assets.

Since property methods are called by the extension itself, the extension will give an error if a property method fails to execute, so it might be misled that the error is originated from the extension itself.

Additionally, when the same schema has used in CompCreator, it seems to ignore errors caused by properties and create the components as it can. I chose to not ignore these user errors in DynamicComponents on purpose, as I find it better to stop the operation with runtime errors instead of creating components with having properties set partially, but it is a personal choice after all, some may prefer extensions that are less "noisy".

To prevent this from happening again I also have made the error messages more descriptive, so it should display the actual message caused by the property itself, I hope this helps.

yes in CompCreator it just ignore the property which is not recognized.

I remember that there used to be a special schema generator for DynamicComponent. Do you have your own topic with a description of the extension? You may want to include the above-published aix in your topic so as not to create a mess.

Yeah, there is. Since schema format itself hasn't changed, I don't want to rush things out, so I'm planning to post the update in extension's own topic (which is on Kodular Community) once everything is ready. Thanks for the heads-up though!