Message8886
I get the following exception:
> Exception in thread "main" java.lang.ClassCastException:
> org.python.core.PySingleton cannot be cast to
> com.xxx.yyyy.Example.ExapleApiJavaType
This happens when I call 'return (ExampleApiJavaType) ExampleApiObject.__tojava__(ExampleApiJavaType.class)', full code here:
package com.xxx.yyyy.example;
import com.xxx.yyyy.example.ExampleApiJavaType;
import org.python.core.PyObject;
import org.python.core.PyString;
import org.python.util.PythonInterpreter;
public class ExampleApiFactory {
private PyObject ExampleApiClass;
public ExampleApiFactory() {
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("from ExampleAPI import ExampleAPI");
ExampleApiClass = interpreter.get("ExampleAPI");
}
public ExampleApiJavaType create (String userid, String passw, String namespace, String URL, String api_level) {
PyObject[] arguments = new PyObject[] {
new PyString(userid),
new PyString(passw),
new PyString(namespace),
new PyString(URL),
new PyString(api_level)
};
PyObject ExampleApiObject = ExampleApiClass.__call__(arguments);
return (ExampleApiJavaType) ExampleApiObject.__tojava__(ExampleApiJavaType.class);
}
}
My type is here:
// Java interface for a building object
package com.xxx.yyyy.example;
public interface ExampleApiJavaType{
public void start_session();
public void stop_session();
public String get_related(String article_id);
public String get_company(String tickerid);
public void save_last_results_to_disk(String filename);
public String get_article(String query_string);
}
I used the example from the book http://www.jython.org/jythonbook/en/1.0/JythonAndJavaIntegration.html#one-to-one-jython-object-factories
Using jython-standalone-2.7-b2 with jdk1.7.0_51
Attached is a complete example. (also found here https://github.com/brianray/embedded-jython)
Also see related case http://bugs.jython.org/issue1103 |
|
Date |
User |
Action |
Args |
2014-07-24 14:53:56 | brianray | set | recipients:
+ brianray |
2014-07-24 14:53:56 | brianray | set | messageid: <1406213636.02.0.544128142239.issue2181@psf.upfronthosting.co.za> |
2014-07-24 14:53:55 | brianray | link | issue2181 messages |
2014-07-24 14:53:54 | brianray | create | |
|