jpype-project / jpype

JPype is cross language bridge to allow Python programs full access to Java class libraries.
http://www.jpype.org
Apache License 2.0
1.12k stars 181 forks source link

TypeError: 'java.lang.String[]' object is not callable #960

Closed Zaoyee closed 3 years ago

Zaoyee commented 3 years ago

Hi, thanks for the package. It helps a lot for my project. I met a problem in my project and unbale to find reason anywhere.

I was trying to call main function of the abc.jar, so I have to pass a String[]. As mentioned in JPype Docs, string array can be defined as following


from com.abc.bce import xxx

args = JString[1](JString("hello_world"))
xxx.main(args)

And I got error like this , I was wondering why

TypeError: 'java.lang.String[]' object is not callable

btw, Is there any other way to assign the value to the JString array, somthing like this would be nice

args = JString[1]
args[0] = JString("wtf-lol-:>") ## I actually got the error by doing this way

Thanks for the help, Respect

pelson commented 3 years ago

I don't know how to do it with the new syntax (that you are showing), but it can be done with the old syntax, as documented at https://jpype.readthedocs.io/en/latest/quickguide.html?highlight=jarray#arrays, with:

>>> s_arr = jp.JArray(jp.JString, 1)(['one', 'two', 'three'])
>>> type(s_arr)
<java class 'java.lang.String[]'>
>>> print(list(s_arr))
['one', 'two', 'three']
Thrameos commented 3 years ago

This one was fixed by the array bug. It was making arrays of type String[][] rather than String[]. It will be fixed in 1.3.