Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jython从python访问java类_Java_Python_Jython - Fatal编程技术网

使用jython从python访问java类

使用jython从python访问java类,java,python,jython,Java,Python,Jython,我用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 fo

我用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)
我的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)
回溯(最近一次呼叫最后一次):
文件“/Users/wolverine/Desktop/project/jython_scripts/customer.py”,第3行,在
客户=客户(1234,“狼”)
TypeError:类(Customer)没有可见的构造函数

免责声明。我刚开始使用java:(

Customer类不在您的包中,而您的构造函数也不是公共的。这就是为什么您会看到错误-python代码看不到构造函数(另一个包中的构造函数)

将构造函数行从

Customer(int _customerId, String _name){

此外,您可能会发现有助于理解公共/受保护/私有/默认的工作方式

Customer(int _customerId, String _name){
public Customer(int _customerId, String _name){