Element values must be a constant expression

@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_TEXTAREA,
            defaultValue = htmlContent)
    @SimpleProperty
    public void HTML(String newContent) {
        htmlContent = newContent;
    }

I have the code above, when I try to compile (Appinventor sources) I get error that :

 error: element value must be a constant expression
    [javac]             defaultValue = htmlContent)

How can I solve this issue? Does this error say's that I need to put defaultValue directly? Can anyone help me? Please?

@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_TEXTAREA, defaultValue = "htmlContent") @SimpleProperty public void HTML(String newContent) { htmlContent = newContent; }

This it how it should be. You were missing " in default value

No, actualy htmlContent is a variable :

private String htmlContent = "******";

I think you should not set defaultValue using the htmlContent string.

because I've tried it with a value 0 (integer) and it returns an error, and finally when I want to set defaultValue to 0 I have to make it like this :

@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_TEXTAREA, defaultValue = "0")

But that string is too large, anyways both thanks for answering

1 Like

Btw, what extension do you want to make :sweat_smile:

1 Like

Sorry, cannot say.

1 Like

Any help? Please?

Can you show me what you import into your extension?

1 Like

as it already has been said, use a constant value rather than a variable

@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_TEXTAREA,
            defaultValue = "your default value")

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.

3 Likes

You can also define the default value as a static final field on the class and reference it in the annotation. We do this in a number of components.

3 Likes