我用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 :(