我在 java 中编写了一个类,我想使用 jython 在 python 中执行它。首先是我得到的错误?
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 在 Users/wolverine/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 :(