![](/img/trans.png)
[英]Does node-java allow anonymous functions to be passed to java as parameters?
[英]problems initializing my java method using node-java
我不是Java專家,但我正在嘗試學習如何使用Node-java。 我試圖運行npm java和gethub node-java上列出的示例之一,但它們不起作用。 我認為我的方法未在我的node.js腳本中正確初始化。 我在Windows 10筆記本電腦上使用JDK / JRE 1.8。 下面是我的簡單代碼示例。 任何幫助,將不勝感激。
var Test = java.import("com.sample.SearchQueryRulesFromTable");
var result = Test.SearchQueryRulesFromTable("C1", "P1");
console.log(result);
節點Java錯誤
nodeJavaBridge.js:233
return java.newInstanceSync.apply(java, args);
^
TypeError: Could not find method
"com.sample.SearchQueryRulesFromTable(java.lang.String,
java.lang.String)" on class "class com.sample.SearchQueryRulesFromTable".
Possible matches:
public com.sample.SearchQueryRulesFromTable() at Error (native)
at javaClassConstructorProxy….
這是我的Java代碼的一部分:
...
public class SearchQueryRulesFromTable {
...
public static final void main(String[] args) {...
javap的結果
Compiled from "SearchQueryRulesFromTable.java
public class com.sample.SearchQueryRulesFromTable {
public com.sample.SearchQueryRulesFromTable();
descriptor: ()V
public static final void main(java.lang.String[]);
descriptor: ([Ljava/lang/String;)V
}
@AlphaVictor我試圖使用似乎無效的node-java構造來調用main方法。 我不知道我在做什么錯。 以下是SearchQueryRulesFromTable中的主要方法:
ItemSearch item1 = new ItemSearch();
item1.setSearchCustomer(args[0]);
item1.setSearchItem(args[1]);
使用:
java.callStaticMethodSync("com.sample.SearchQueryRulesFromTable",
"ItemSearch(item1)","C1", "P1", function(err, results) {
if(err) {console.error(err);
javaLangSystem.out.printlnSync('test complete! '+ results);return;}
錯誤:
C:\Users\rdouglas\AppData\Roaming\npm\node_modules\NewProjects\08-
egilerapp1\classes>node test.js
(node) sys is deprecated. Use util instead.
C:\Users\rdouglas\AppData\Roaming\npm\node_modules\NewProjects\08-
egilerapp1\classes\test.js:14
var result =
java.callStaticMethodSync("com.sample.SearchQueryRulesFromTable",
"ItemSearch","C1", "P1")
^
錯誤:
Could not find method "ItemSearch(java.lang.String, java.lang.String)" on
class "class com.sample.SearchQueryRulesFromTable". No methods with that
name.
at Error (native)
at Object.<anonymous>
(C:\Users\rdouglas\AppData\Roaming\npm\node_modules\NewProjects\08-
egilerapp1\classes\test.js:14:19)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3
TypeError: Could not find method
"com.sample.SearchQueryRulesFromTable(java.lang.String,
java.lang.String)" on class "class com.sample.SearchQueryRulesFromTable".
該錯誤告訴您,您試圖在接受兩個String
參數的類SearchQueryRulesFromTable
上調用構造函數。 在該類上沒有定義此類構造函數。
您的代碼正在嘗試在此處調用此不存在的構造函數:
SearchQueryRulesFromTable("C1", "P1");
根據您要嘗試執行的操作,您可能希望改為在SearchQueryRulesFromTable
調用main
方法,然后將其傳遞給String[]
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.