gpt4 book ai didi

java - JPype - 导入和调用方法的问题!

转载 作者:太空宇宙 更新时间:2023-11-03 19:38:22 24 4
gpt4 key购买 nike

我在下面附上我的代码

from jpype import *
from javax.swing import JFrame

classpath = "-Djava.class.path=praat.jar"
startJVM(getDefaultJVMPath(),"-ea",classpath)

frame = javax.swing.JFrame("Hello JPype")
label = javax.swing.JLabel("Hello JPype!", JLabel.CENTER)
frame.add(label)
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
frame.setSize(200, 100)
frame.show()
shutdownJVM()

当我运行这个程序时,我收到一个错误。

    /Library/Python/2.6/site-packages/jpype/_pykeywords.py:18: DeprecationWarning: the sets module is deprecated
import sets
2010-02-01 22:26:27.473 Python[754:d07] Apple AWT Java VM was loaded on first thread -- can't start AWT.
Traceback (most recent call last):
File "swing.py", line 10, in <module>
frame = javax.swing.JFrame("Hello Jython")
File "/Library/Python/2.6/site-packages/jpype/_jpackage.py", line 53, in __call__
raise TypeError, "Package "+self.__name+" is not Callable"
TypeError: Package javax.swing.JFrame is not Callable

有什么办法可以解决这个问题吗?普通的 Hello World 程序工作正常,但是当我尝试导入包时,我遇到了类似的问题。

最佳答案

将 Java 运行时库 (rt.jar) 添加到类路径中,然后重试。该错误表明,无法找到 JFrame,但它位于 rt.jar 内。

关于java - JPype - 导入和调用方法的问题!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2178532/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com