![](/img/trans.png)
[英]Cannot convert value of type 'java.lang.String' to required type
[英]JPype1=0.7.0: TypeError: Unable to convert str ro java type class java.lang.String
当使用 JPype1 将 python str 转换为 java.lang.String 时,我在某些 Windows 机器上出现错误,而其他 Windows 机器则没有。
文件“lib\\site-packages\\jpype_jobject.py”,第 86 行,在
__new__
类型错误:无法将 str 转换为 java 类型类 java.lang.String
我使用 PyInstaller 3.5 将代码打包到“exe”中,然后在具有相同 JDK 的几台 Windows 机器上运行该 exe,但得到不同的结果。
编译环境:windows、python 3.6.5、JPype1 0.7.0、PyInstaller 3.5、
运行环境: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"))
我试图阅读源代码“ https://github.com/jpype-project/jpype.git ”,但没有得到任何。
任何人都可以在这里引导我朝着正确的方向前进吗?
最后我发现另一个错误日志说JVM没有成功启动。 因为机器上有两个版本的jdk。 虽然“java -version”显示为 1.8,但 %JAVA_HOME% 仍然是 1.7。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.