我想在应该在移动设备上运行的javafx应用程序的fxml文件中使用脚本化事件处理程序。
我正在使用jfxmobile-plugin的版本2交叉编译手机版,该版本使用gluonvm:
org.javafxports:jfxmobile-plugin:2.0.29
javafxports通常在iOS和/或Android上支持FXML脚本事件处理程序吗?
我正在尝试跟踪fxml文件,该文件可在台式机,Android和iOS上运行:
<?xml version="1.0" encoding="UTF-8"?>
<?language javascript?>
...
<Button fx:id="button" onMouseClicked="label.setText('Button has been clicked from JavaScript');" text="%button.text" />
在Android和iOS上,我收到以下异常:
System.err(19642): Exception in Application start method
System.out(19642): QuantumRenderer: shutdown
System.err(19642): java.lang.reflect.InvocationTargetException
System.err(19642): at java.lang.reflect.Method.invoke(Native Method)
System.err(19642): at java.lang.reflect.Method.invoke(Method.java:372)
System.err(19642): at javafxports.android.DalvikLauncher$1.run(DalvikLauncher.java:188)
System.err(19642): at java.lang.Thread.run(Thread.java:818)
System.err(19642): Caused by: java.lang.RuntimeException: Exception in Application start method
[MALI][Gralloc](193): [+]hnd:0x7fb884c000, fd:27, ion_hnd(0x4), req_format(0x1), int_fmt(0x1) byte_stride(3200), flags(0x4), usage(0xb00), size(3788800), alloc_size(3788800) 800(800)X1184(1184) pid(193) sec (0)
System.err(19642): at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
System.err(19642): at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$138(LauncherImpl.java:182)
System.err(19642): at com.sun.javafx.application.LauncherImpl.access$lambda$1(LauncherImpl.java)
System.err(19642): at com.sun.javafx.application.LauncherImpl$$Lambda$2.run(Unknown Source)
System.err(19642): ... 1 more
System.err(19642): Caused by: javafx.fxml.LoadException: Error resolving onMouseClicked='label.setText('Button has been clicked from JavaScript');', either the event handler is not in the Namespace or there is an error in the script.
System.err(19642): file:/data/app/com.indsp.software.playground.javafxmobiledemo.demoapp-1/base.apk!/com/indsp/software/playground/javafxmobiledemo/demoapp/scenes/Scene1.fxml:46
HAL(19642): loaded HAL id=gralloc path=/system/lib/hw/gralloc.mt8163.mali.so hmi=0x0 handle=0xf46f9154
[MALI][Gralloc](19642): [+]r_hnd:0xf7a2e728, fd:44, ion_hnd(0x4), req_format(0x1), int_fmt(0x1) byte_stride(3200), flags(0x4), usage(0xb00), size(3788800), alloc_size(3788800) 800(800)X1184(1184) pid(19642) sec (0)
Kernel(193): [371573.005712] <2> (2)[236:Binder_1][name:ion_mm_heap&][ION][ion_dbg] alloc_pages order=2 cache=0
System.err(19642): at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2597)
System.err(19642): at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:103)
System.err(19642): at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:610)
System.err(19642): at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:770)
System.err(19642): at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2823)
System.err(19642): at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2532)
System.err(19642): at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
System.err(19642): at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
System.err(19642): at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
System.err(19642): at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
System.err(19642): at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
System.err(19642): at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3116)
System.err(19642): at com.indsp.software.playground.javafxmobiledemo.demoapp.DemoApp.start(DemoApp.java:21)
System.err(19642): at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$145(LauncherImpl.java:863)
System.err(19642): at com.sun.javafx.application.LauncherImpl.access$lambda$8(LauncherImpl.java)
System.err(19642): at com.sun.javafx.application.LauncherImpl$$Lambda$9.run(Unknown Source)
System.err(19642): at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$158(PlatformImpl.java:326)
System.err(19642): at com.sun.javafx.application.PlatformImpl.access$lambda$6(PlatformImpl.java)
System.err(19642): at com.sun.javafx.application.PlatformImpl$$Lambda$7.run(Unknown Source)
System.err(19642): at com.sun.javafx.application.PlatformImpl.lambda$null$156(PlatformImpl.java:295)
System.err(19642): at com.sun.javafx.application.PlatformImpl.access$lambda$18(PlatformImpl.java)
System.err(19642): at com.sun.javafx.application.PlatformImpl$$Lambda$19.run(Unknown Source)
System.err(19642): at java.security.AccessController.doPrivileged(AccessController.java:52)
System.err(19642): at com.sun.javafx.application.PlatformImpl.lambda$runLater$157(PlatformImpl.java:294)
System.err(19642): at com.sun.javafx.application.PlatformImpl.access$lambda$5(PlatformImpl.java)
System.err(19642): at com.sun.javafx.application.PlatformImpl$$Lambda$6.run(Unknown Source)
System.err(19642): at com.sun.glass.ui.monocle.RunnableProcessor.runLoop(RunnableProcessor.java:93)
System.err(19642): at com.sun.glass.ui.monocle.RunnableProcessor.run(RunnableProcessor.java:52)
System.err(19642): ... 1 more
答案 0 :(得分:1)
根据您得到的错误:
...事件处理程序不在命名空间中,或者脚本中有错误。
您可以在FXMLLoader
类中查找打印的消息,然后您会发现:
if (handlerName.length() == 0 || scriptEngine == null) {
throw constructLoadException("Error resolving " + attribute.name + "='" + attribute.value
+ "', either the event handler is not in the Namespace or there is an error in the script.");
}
eventHandler = new ScriptEventHandler(handlerName, scriptEngine);
因此,似乎没有scriptEngine
。
要确认这一点,您可以尝试在台式机和移动设备上运行一个简单的测试:
ScriptEngineManager manager = new ScriptEngineManager();
if (manager != null) {
for (ScriptEngineFactory factory : manager.getEngineFactories()) {
System.out.println("factory: " + factory.getEngineName() + " " + factory.getLanguageName() + " " + factory.getExtensions());
}
}
在台式机上打印时:
Oracle Nashorn ECMAScript [js]
在移动设备(包括Android和iOS)上,它不会打印任何内容。
因此,这确认了移动设备不支持脚本事件处理程序。
就个人而言,我还是不喜欢在台式机上使用它们。