2013-04-05 68 views
5

我已經在worklight項目的適配器中編寫了一些java代碼。當I M試圖調用Java方法,我得到一個錯誤說Ecma錯誤:TypeError:無法調用屬性

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

我按照下面的鏈接正好規定的程序。 Using Java in Adapters

這是我的項目結構。這個結構有什麼問題,或者我應該添加更多什麼?

enter image description here

我這是如何試圖調用適配器impl.js java的非靜態方法

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

}

回答

6

我們已經確定了另一種可能的解決了這一點。

  • 更改Java編譯器級至1.6以及默認的JRE到1.6:

Compiler level JRE version

+0

我有一個類似的問題,@christianmenens在[本se post]迴應(http://stackoverflow.com/questions/16614742/ecma-typeerror-calling- java-class-from-worklight-adapter?rq = 1)解決了我的問題 – 2016-08-09 02:53:49

+0

你發現了它!我也必須從服務器中刪除以前的「格式錯誤」的應用程序並重建WAR – 2017-12-01 14:52:30

0

確保你的包融爲一體,例如啓動將其重命名爲「com.classes」。

+0

您好,感謝您的回覆。但我也嘗試過。我收到了同樣的錯誤。 – 2013-04-05 08:20:09

0

嘗試添加括號,當你實例化對象:

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

是的,我也這麼做..沒有改變的錯誤.. – 2013-04-05 12:28:29

0

檢查您的項目文件,並確保它在它的右側buildCommand標籤。

<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> 

閱讀更多:ECMA TypeError calling Java class from Worklight adapter

相關問題