jython / jython3

A sandboxed attempt at v3 (not maintained)
Other
299 stars 59 forks source link

Error on import javafx control #38

Open f-lima opened 6 years ago

f-lima commented 6 years ago

Copy the code below to test.py and run it

from javafx.scene.control import TabPane
print("Ok")

It returns an error saying:

java.lang.ExceptionInInitializerError Caused by: java.lang.IllegalStateException: Toolkit not initialized

Complete Error report:

Traceback (most recent call last):
File "test.py", line 1, in <module>
    from javafx.scene.control import TabPane
java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.python.core.Py.loadAndInitClass(Py.java:991)
at org.python.core.Py.findClassInternal(Py.java:926)
at org.python.core.Py.findClassEx(Py.java:977)
at org.python.core.packagecache.SysPackageManager.findClass(SysPackageManager.java:133)
at org.python.core.packagecache.PackageManager.findClass(PackageManager.java:33)
at org.python.core.packagecache.SysPackageManager.findClass(SysPackageManager.java:122)
at org.python.core.PyJavaPackage.__findattr_ex__(PyJavaPackage.java:134)
at org.python.core.PyObject.__findattr__(PyObject.java:946)
at org.python.core.imp.importFromAs(imp.java:1160)
at org.python.core.imp.importFrom(imp.java:1132)
at org.python.pycode._pyx0.f$0(test.py:3)
at org.python.pycode._pyx0.call_function(test.py)
at org.python.core.PyTableCode.call(PyTableCode.java:167)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1386)
at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:296)
at org.python.util.jython.run(jython.java:362)
at org.python.util.jython.main(jython.java:142)
Caused by: java.lang.IllegalStateException: Toolkit not initialized
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:273)
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:268)
at com.sun.javafx.application.PlatformImpl.setPlatformUserAgentStylesheet(PlatformImpl.java:550)
at com.sun.javafx.application.PlatformImpl.setDefaultPlatformUserAgentStylesheet(PlatformImpl.java:512)
at javafx.scene.control.Control.<clinit>(Control.java:87)
... 20 more

java.lang.ExceptionInInitializerError: java.lang.ExceptionInInitializerError

Something is happening at import command that is generating this error. As you can see at code, I am just importing but not using the imported class.

Added: I just noticed that the same error occurs when I try import Control directly. Appears that the error are in creation of this class and classes that have Control as parent class, for any reason. By the other side, try to import classes that have Pane as parent works, even having Pane Control as his parent class. I don't know if this information helps.

Thanks for your help.

Jython version: 2.7.0

If this Issue was at wrong project please let me know where to put it. Thanks.

jeff5 commented 6 years ago

Jython 3 is an unsupported shot at Python 3.5. Bugs can be raised against 2.7 at bugs.jython.org, or (second best) at https://github.com/jythontools/jython .

However, I don't yet see this as a bug. Here I think the problem could be that a class imported by Jython is initialised at that point (not just declared as in a Java import). In Python generally, you probably know, an import executes the module body.

In Java, initialisation occurs when execution first handles a member of the imported class.

I don't know any FX but it appears that the TabPane class initialisation may only correctly occur after the toolkit is initialised, so this might be solved by relocating that and similar imports until after that.

f-lima commented 6 years ago

Thanks. I will analise what you said and check if move the import solve it.