我有一个试图从 python 访问的 java 外观类,所以我决定使用JPype
. 我的外观类只有一个带有四个参数的构造函数(无默认值)
public facade(String a, String b, List<String> c, List<String> d){
...
}
初始化类的新实例时,我似乎无法正确获取类型。我尝试的一切都给出了同样的错误:
File ".../main.py", line 34, in __init__
facadeinstance = Facade(jpype.JString(s1), jpype.JString(s2),jpype.JArray(jpype.java.lang.String, 1)(s3), jpype.JArray(jpype.java.lang.String, 1)(s4))
File "/usr/local/lib/python2.7/dist-packages/jpype/_jclass.py", line 79, in _javaInit
self.__javaobject__ = self.__class__.__javaclass__.newClassInstance(*args)
RuntimeError: No matching overloads found. at src/native/common/jp_method.cpp:121
我知道JPype
正在工作。我已经尝试了几种包装器组合来以正确的形式获取数据,但没有运气。
相关代码:
import jpype
s1 = "something"
s2 = "something else"
s3 = ["something in a list"]
s4 = ["Something else in a list"]
jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.class.path=" + JavaJarDir)
myLib = jpype.JPackage('myLib')
Facade = myLib.Facade # class loads fine, resources printed to stdout
# The error occurs on the next line
FacadeInstance = Facade(jpype.JString(s1), jpype.JString(s2), jpype.JArray(jpype.java.lang.String, 1)(s3), jpype.JArray(jpype.java.lang.String, 1)(s4))
jpype.shutdownJVM()