Hello,

thanks for your answer and explanation.
I created issue in JavaFX JIRA: https://javafx-jira.kenai.com/browse/RT-32035

Regards, Jiri

--
http://www.dredwerkz.cz
+420 739 575 905
218 659 431
http://www.plurk.com/goddard

---------- Původní zpráva ----------
Od: Weiqi Gao <weiqigao@gmail.com>
Datum: 31. 7. 2013
Předmět: Re: [Jython-users] Jython & JavaFX


A little experiment shows that if you change the line

from javafx.scene.control import Label

to

import javafx.scene.control

and then change the line

label = Label("Hello, World!")

to use the fully qualified name

label = javafx.scene.control.Label("Hello, World!")

the program would have behaved as one expected.


A file you the import line alone

# foo.py
from javafx.scene.control import Label

or even

# foo.py
import javafx.scene.control.Label

would have caused the same stack trace. But

# foo.py
import javafx.scene.control

doesn't.


Remember unlike in Java, import statements in Jython are executable
code. And importing a specific class (rather than a package) seems to
cause the class to be loaded and therefore causes its static initializer
<clinit> to be executed, which in this case causes the exception to be
thrown.

You can also move the

from javafx.scene.control import Label

line to a later spot (like right before the line where the Label object
is constructed) to avoid the exception.

The root cause of this problem, though, seems to lie with JavaFX 8. The
exception can be reproduced in Java with a simple Class.forName() call

public class Hello {
public static void main(String[] args) throws Exception {
Class.forName("javafx.scene.control.Label");
}
}

I'd say file a bug with JavaFX

https://javafx-jira.kenai.com/secure/Dashboard.jspa

--
Weiqi Gao
weiqigao@gmail.com
http://weiqigao.blogspot.com/


On 07/31/2013 09:27 AM, Jiri Prajzner wrote:
> Hello,
>
> since the JDK8 preview is available, I've thought that it'd be easier to
> use Jython & JavaFX. And I was right :)
> I don't have to set the -Dpython.path=<path to jfxrt.jar"> anymore.
> However, one issue remains.
> When I try to use javafx.scene.control.Label class, it throws this
> exception:
> Traceback (most recent call last):
> File "hello.jy", line 4, in <module>
> from javafx.scene.control import Label
> java.lang.ExceptionInInitializerError
> at java.lang.Class.forName0(Native Method)
> at java.lang.Class.forName(Class.java:339)
> at org.python.core.Py.loadAndInitClass(Py.java:929)
> at org.python.core.Py.findClassInternal(Py.java:864)
> at org.python.core.Py.findClassEx(Py.java:915)
> at
> org.python.core.packagecache.SysPackageManager.findClass(SysPackageMa
> nager.java:133)
> at
> org.python.core.packagecache.PackageManager.findClass(PackageManager.
> java:28)
> at
> org.python.core.packagecache.SysPackageManager.findClass(SysPackageMa
> nager.java:122)
> at
> org.python.core.PyJavaPackage.__findattr_ex__(PyJavaPackage.java:137)
>
> at org.python.core.PyObject.__findattr__(PyObject.java:879)
> at org.python.core.imp.importFromAs(imp.java:1034)
> at org.python.core.imp.importFrom(imp.java:1006)
> at org.python.pycode._pyx0.f$0(hello.jy:23)
> at org.python.pycode._pyx0.call_function(hello.jy)
> at org.python.core.PyTableCode.call(PyTableCode.java:165)
> at org.python.core.PyCode.call(PyCode.java:18)
> at org.python.core.Py.runCode(Py.java:1302)
> at
> org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:235
> )
> at org.python.util.jython.run(jython.java:308)
> at org.python.util.jython.main(jython.java:137)
> Caused by: java.lang.NullPointerException
> at
> com.sun.javafx.tk.quantum.QuantumToolkit.isSupported(QuantumToolkit.j
> ava:1249)
> at
> com.sun.javafx.application.PlatformImpl.isSupported(PlatformImpl.java
> :452)
> at
> com.sun.javafx.application.PlatformImpl$11.run(PlatformImpl.java:548)
>
> at java.security.AccessController.doPrivileged(Native Method)
> at
> com.sun.javafx.application.PlatformImpl.setPlatformUserAgentStyleshee
> t(PlatformImpl.java:544)
> at
> com.sun.javafx.application.PlatformImpl.setDefaultPlatformUserAgentSt
> ylesheet(PlatformImpl.java:479)
> at javafx.scene.control.Control.<clinit>(Control.java:81)
> ... 20 more
>
> java.lang.ExceptionInInitializerError: java.lang.ExceptionInInitializerError
>
> and here's the code:
>
> # hello.py
> from javafx.application import Application
> from javafx.scene import Scene
> from javafx.scene.control import Label
> from javafx.scene.layout import AnchorPane
>
>
> class Hello(Application):
> def start(self, stage):
> stage.setTitle("Hello, World!")
>
> root = AnchorPane()
> label = Label("Hello, World!")
> root.getChildren().add(label)
>
> scene = Scene(root, 100, 40)
> stage.setScene(scene)
>
> stage.show()
>
>
> if __name__ == '__main__':
> Application.launch(Hello().class, [])
>
> Im' running Windows 7 64-bit with JDK8 b94 and Jython 2.7 b1
> I'd love to use Jython & JavaFX and I'm willing to work on this together.
>
> Regards, Jiri
> --
> http://www.dredwerkz.cz
> +420 739 575 905
> 218 659 431
> http://www.plurk.com/goddard
>
>
> ------------------------------------------------------------------------------
> Get your SQL database under version control now!
> Version control is standard for application code, but databases havent
> caught up. So what steps can you take to put your SQL databases under
> version control? Why should you start doing it? Read more to find out.
> http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
>
>
>
> _______________________________________________
> Jython-users mailing list
> Jython-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jython-users
>


------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent
caught up. So what steps can you take to put your SQL databases under
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users