-
-
Notifications
You must be signed in to change notification settings - Fork 518
Problem importing extended java classes. #856
Comments
It looks like this is caused by the compiler not realizing that foo.class is not a python module. If so it should be easy to fix, but is a different bug than I wanted to illustrate, which involved subclassing an Android view. I'll look at my application again to see if there're indeed two issues at play here. |
Does the same error occur if you use a different name for the module, class, and method? The test suite already contains a bunch of examples of importing from a Java class; I can only assume that there's a namespace collision happening somewhere. |
The name of the class within the java package doesn't matter. It seems that the subclassing isn't the issue, and the subclass definition can be removed from the example. As far as I can tell what happens is that if the main python module // Create an instance of the class; if it isn't a module, we haven't been able to import.
try {
java.lang.reflect.Constructor constructor = java_class.getConstructor();
python_module = (org.python.types.Module) constructor.newInstance();
} catch (ClassCastException cce) {
throw new java.lang.ClassNotFoundException("Found " + import_name + " class, but class is not a module");
} The exception is not caught, and the importer doesn't fall back to native import because it's expecting the process to fail with I don't know the code, really, so this is only a guess. Things aren't set up for development right now; I'll tinker with this in a few days and report back. |
Consider the files
foo.java
,t1.py
,t2.py
.The file t2 extends the defined java class:
and the resulting class is used from t1:
The initialization of bar fails with
The text was updated successfully, but these errors were encountered: