3
我在java中編寫了一個類,我想用python執行jython。 首先我得到的錯誤?使用jython從python訪問java類
Traceback (most recent call last):
File "/Users/wolverine/Desktop/project/jython_scripts/customer.py", line 3, in <module>
customer = Customer(1234,"wolf")
TypeError: No visible constructors for class (Customer)
我的Java類格式:
public class Customer {
public final int customerId;
public final String name;
public double balance;
/*
* Constructor
*/
Customer(int _customerId, String _name){
customerId = _customerId;
name = _name;
balance = 0;
}
我的Python 2行腳本
import Customer
customer = Customer(1234,"wolf")
print customer.getName()
的目錄結構就像
folder/customer.py folder/Customer.java folder/Customer.jar
我去了文件夾,並做了
%javac -classpath Customer.jar *.java
然後我的Jython是在用戶/狼獾/ Jython的/ Jython的
要執行我做這
%/Users/wolverin/jython/jython ~/Desktop/folder/customer.py
又一次的錯誤是:
Traceback (most recent call last):
File "/Users/wolverine/Desktop/project/jython_scripts/customer.py", line 3, in <module>
customer = Customer(1234,"wolf")
TypeError: No visible constructors for class (Customer)
免責聲明。我剛開始使用java :(
工程就像一個魅力。謝謝 – Fraz