在這裏,我附上相關JPype - 問題導入和調用方法!
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程序工作正常,但是當我試圖導入包時,我遇到了類似的問題。
不幸的是我試過這個,它不起作用。我在Linux和Mac系統上嘗試過,它仍然會拋出同樣的錯誤:(第二個想法的 – Vivek 2010-02-02 05:02:11