简体   繁体   English

Jpype将参数传递给Java

[英]Jpype passing arguments to Java

I have a java programmer with following line 我有一个以下行的Java程序员

service.loadPropertiesForItems(Inbox, new PropertySet(ItemSchema.Subject, ItemSchema.Body));

Program calls classes and methods from external jars. 程序从外部jar调用类和方法。

I want to write equivalent code in python which calls external jars like my java program does. 我想在python中编写等效的代码,就像我的java程序一样,它调用外部jar。 Using Jpype I implemented the code but it fails on following line 使用Jpype我实现了代码,但是在下一行中失败了

service.loadPropertiesForItems(inbox, ewsPkg.PropertySet(ewsPkg.ItemSchema.Subject,   ewsPkg.ItemSchema.Body))

Here PropertySet, ItemSchema are classes which I use from external jar. 在这里,PropertySet,ItemSchema是我从外部jar使用的类。 ItemSchema.Subject and ewsPkg.ItemSchema.Body are class type ItemSchema.Subject和ewsPkg.ItemSchema.Body是类类型

Running the code I get following error on line mentioned above - 运行代码我在上面提到的行中遇到以下错误-

service.loadPropertiesForItems(inbox, ewsPkg.PropertySet(ewsPkg.ItemSchema.Subject, ewsPkg.ItemSchema.Body))
File "C:\Python27\lib\site-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

Thanks 谢谢

As suggested by Martin https://github.com/originell/jpype/issues/117 正如马丁的建议https://github.com/originell/jpype/issues/117

following code works well 以下代码效果很好

ItemSchema = ewsPkg.ItemSchema
PropertyDefinition = ewsPkg.PropertyDefinition
Subject = ItemSchema.Subject
Body = ItemSchema.Body

args = JArray(PropertyDefinition)([ItemSchema.Subject, Body])
PropertySet = ewsPkg.PropertySet(args)

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

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