Ecma Error: TypeError: Cannot call property

2020-01-29 02:04发布

I have written some java code in an adapter in worklight project. when i m trying to call the java method, i am getting an error saying

"responseID":"6","errors": {Ecma Error: TypeError: Cannot call property downloadFile in object JavaPackage java.classes.FileIOPlugin]. It is not a function, it is \"object\".}

I have followed the procedure exactly stated in the following link. Using Java in Adapters

this is my project structure. Is there something wrong with this structure or should i add anything more to this?

enter image description here

This is how i am trying to call the java non-static method in adapter-impl.js

function downloadFile() {
    var fileInstance = new com.worklight.JavaCode.FileIOPlugin();
    return
    {   result: fileInstance.downloadFile();    };

}

4条回答
男人必须洒脱
2楼-- · 2020-01-29 02:14

We have identified another possible solution to this.

  • Change Java compiler level to 1.6 as well as default JRE to 1.6:

Compiler level JRE version

查看更多
劫难
3楼-- · 2020-01-29 02:24

Make sure your package starts with com, e.g. rename it to "com.classes".

查看更多
Evening l夕情丶
4楼-- · 2020-01-29 02:26

Check your .project file and make sure it has the right buildCommand tags in it.

<buildCommand>
        <name>org.eclipse.jdt.core.javabuilder</name>
        <arguments>
        </arguments>
    </buildCommand>
    <buildCommand>
        <name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
        <arguments>
        </arguments>
    </buildCommand>
    <buildCommand>
        <name>org.eclipse.wst.common.project.facet.core.builder</name>
        <arguments>
        </arguments>
    </buildCommand>
    <buildCommand>
        <name>com.worklight.studio.plugin.WorklightProjectBuilder</name>
        <arguments>
        </arguments>
    </buildCommand>
    <buildCommand>
        <name>org.eclipse.wst.validation.validationbuilder</name>
        <arguments>
        </arguments>
    </buildCommand>

Read more at: ECMA TypeError calling Java class from Worklight adapter

查看更多
够拽才男人
5楼-- · 2020-01-29 02:28

Try adding the parenthesis when you instantiate your object:

var fileInstance = new com.worklight.JavaCode.FileIOPlugin()
查看更多
登录 后发表回答