とクラスキャスト例外私が作成しようとJythonの中でオブジェクトをキャストし、私は次のエラーを受信していています:ここでのJython - PyObject
Exception in thread "MainThread" java.lang.ClassCastException: org.python.core.PySingleton cannot be cast to resources.ixia.IxNetType
at resources.ixia.IxNetFactory.create(IxNetFactory.java:34)
at resources.ixia.IxiaTest.run(IxiaTest.java:34)
at resources.ixia.IxiaTest.<init>(IxiaTest.java:14)
at resources.ixia.IxiaTest.main(IxiaTest.java:42)
はコードです:については
import org.python.core.PyObject;
import org.python.util.PythonInterpreter;
public class IxNetFactory {
private PyObject ixNetClass;
private PythonInterpreter interpreter;
public IxNetFactory(String script_dir) {
script_dir=script_dir.replace("\\", "/");
interpreter = new PythonInterpreter();
interpreter.exec("import sys");
interpreter.exec("sys.path.append('"+script_dir+"')");
interpreter.exec("import time");
interpreter.exec("import os");
interpreter.exec("from ixnetworks import IxNet");
//interpreter.exec("from utils import sm");
//interpreter.exec("from utils import cpf");
ixNetClass = interpreter.get("IxNet");
}
/*
* Create an IxNet object
*
* Usage: ixNet.create();
*/
public IxNetType create() {
PyObject ixNetObject = ixNetClass.__call__();
return (IxNetType)ixNetObject.__tojava__(IxNetType.class);
}
public void close() {
interpreter.close();
}
}
私の人生は私が間違っていることを理解することができません。私が読んだことのすべてから、私はこれを正しくやっているようですが、それを働かせることはできません。
のJythonの経験を持つ人は、私はそれがはるかに高く評価されるだろう間違ってやっているものを私に伝えることができれば。
私は'IxNet'と' IxNetType'がどのように見えるのだろうか。これらのタイプのソースが閉じている場合は、露出を最小限に抑えながら問題を再現するような方法で書き直すことができますか? –