Ecma Error: TypeError: Cannot call property

谁说胖子不能爱 提交于 2019-12-17 09:57:56

问题


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



来源:https://stackoverflow.com/questions/15826456/ecma-error-typeerror-cannot-call-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!