Ecma Error: TypeError: Cannot call property

2020-01-29 02:05发布

问题:

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?

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();    };

}

回答1:

We have identified another possible solution to this.

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



回答2:

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



回答3:

Try adding the parenthesis when you instantiate your object:

var fileInstance = new com.worklight.JavaCode.FileIOPlugin()


回答4:

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