简体   繁体   English

使用node-java初始化我的java方法时出现问题

[英]problems initializing my java method using node-java

I'm not a java jock, but I'm trying to learn how to use node-java. 我不是Java专家,但我正在尝试学习如何使用Node-java。 I tried to run one of the examples listed on npm java and gethub node-java and they don't work. 我试图运行npm java和gethub node-java上列出的示例之一,但它们不起作用。 I think my method is not initialize in my node.js script correctly. 我认为我的方法未在我的node.js脚本中正确初始化。 I'm using JDK/JRE 1.8 on a Window 10 laptop. 我在Windows 10笔记本电脑上使用JDK / JRE 1.8。 Below is my simple code example. 下面是我的简单代码示例。 Any help would be appreciated. 任何帮助,将不胜感激。

var Test = java.import("com.sample.SearchQueryRulesFromTable");

var result = Test.SearchQueryRulesFromTable("C1", "P1");
console.log(result);

Error in node-java 节点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….

Here is part of my java code: 这是我的Java代码的一部分:

...
public class SearchQueryRulesFromTable {
...
public static final void main(String[] args) {...

Results of javap 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 I have tried to call the main method using node-java constructs that didn't seem to work. @AlphaVictor我试图使用似乎无效的node-java构造来调用main方法。 I don't know what I'm doing wrong. 我不知道我在做什么错。 Below is the main method in SearchQueryRulesFromTable: 以下是SearchQueryRulesFromTable中的主要方法:

ItemSearch  item1 = new ItemSearch();

item1.setSearchCustomer(args[0]);
item1.setSearchItem(args[1]); 

Using: 使用:

java.callStaticMethodSync("com.sample.SearchQueryRulesFromTable", 
"ItemSearch(item1)","C1", "P1", function(err, results) {    
if(err) {console.error(err); 
javaLangSystem.out.printlnSync('test complete! '+ results);return;}   

Error: 错误:

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")
              ^

Error: 错误:

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

This error tells you that you have tried to call a constructor on class SearchQueryRulesFromTable that accepts two String arguments. 该错误告诉您,您试图在接受两个String参数的类SearchQueryRulesFromTable上调用构造函数。 There is no such constructor defined on that class. 在该类上没有定义此类构造函数。

Your code is attempting to call this non-existent constructor here: 您的代码正在尝试在此处调用此不存在的构造函数:

SearchQueryRulesFromTable("C1", "P1");

Depending on what you are trying to do, you may want to call the main method within SearchQueryRulesFromTable instead, and pass it a String[] . 根据您要尝试执行的操作,您可能希望改为在SearchQueryRulesFromTable调用main方法,然后将其传递给String[]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM