在这里我将我的代码附加到下面
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程序运行良好,但是当我尝试导入包时,我得到了类似的问题。
发布于 2010-02-02 01:46:52
将Java运行时库(rt.jar)添加到类路径中,然后重试。该错误表明,无法找到JFrame,但它在rt.jar中。
发布于 2010-02-02 06:31:28
如果将JFrame导入本地名称空间,请使用该名称空间而不使用完整名称空间:
frame = JFrame("Hello Jython")与JLabel相同,但请记住先导入它。
要使用完整的名称空间,您需要使用import javax.swing而不是from javax.swing import JFrame。
https://stackoverflow.com/questions/2178532
复制相似问题