从Java调用Python并传递参数时出错

从Java调用Python并传递参数时出错,java,jython,Java,Jython,下面是从Java调用Python的给定代码 public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new test1( ).setVisible(true); } }); try { PythonInterpreter.initializ

下面是从Java调用Python的给定代码

public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new test1( ).setVisible(true);
        }
    });
    try {
        PythonInterpreter.initialize(System.getProperties(), System.getProperties(), new String[0]);
        PythonInterpreter interp = new PythonInterpreter();
        interp.set("firstName", args[0]);
        interp.set("lastName", args[1]);
        interp.execfile("‪C:\\Users\\priyank\\Desktop\\pythontest.py");
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}
我得到以下例外情况:

java.lang.ArrayIndexOutOfBoundsException: 0" error.. 

为什么会出现此错误?

启动应用程序时,似乎没有传递任何参数。args数组为空(size=0),但您正试图访问不存在的第一个元素(索引0)

管道可能是更好的解决方案。看看这条线:

.

将值更改为

interp.set("firstName", args[1]);
interp.set("lastName", args[2]);

它会工作的,因为第一个值是python脚本文件名,但我们没有添加它,请检查。

我已经添加了两个字符串到它,但我仍然得到相同的错误,请帮助我重写它,如果你能告诉我如何从java向python传递参数。我不理解这个示例,对不起,我是Java和Python新手,你不懂什么?