简体   繁体   中英

JPype1=0.7.0: TypeError: Unable to convert str ro java type class java.lang.String

When using JPype1 to convert python str to java.lang.String, i got an error on some windows machines while other windows machines not.

File "lib\\site-packages\\jpype_jobject.py", line 86, in __new__
TypeError: Unable to convert str to java type class java.lang.String

I pack up the codes into "exe" using PyInstaller 3.5, then run the exe on several windows machines with same JDK, but get different results.

Compile Environment: windows, python 3.6.5 , JPype1 0.7.0, PyInstaller 3.5,
Running Environment: windows, JDK 1.8

import jpype
from jpype import JClass

jpype.startJVM(jpype.getDefaultJVMPath())
mystr = "i'm a string"
jstr = jpype.JObject(mystr, JClass("java.lang.String"))

I tried to read the source code " https://github.com/jpype-project/jpype.git " but didn't get any.

Can anyone lead me in the right direction here?

Finally i found another error log said that JVM was not started successfully. Because there're two versions of jdk on the machine. Although "java -version" shows 1.8, but %JAVA_HOME% is still 1.7.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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