我想问,如果有人曾经使用胶Char魅力下降插件的IOS屏幕方向的问题?空指针从阅读屏幕方向从胶Char魅力下降
JFXMobile插件:org.javafxports:jfxmobile-plugin:1.3.2
魅力版本:com.gluonhq:charm:4.2.0
downConfig {
version = '3.1.0'
plugins 'display', 'lifecycle', 'statusbar', 'storage', 'orientation'
}
当我尝试调用它,就像这样:
Services.get(OrientationService.class).ifPresent(service -> {
onOrientationChange(service.orientationProperty(), null, service.getOrientation().orElse(Orientation.VERTICAL));
service.orientationProperty().addListener(this::onOrientationChange);
});
我得到的控制台上的异常:
Exception in Preloader start method
2017-02-06 10:43:37.104693 MyApp[447:282589] Orientation is Unknown
QuantumRenderer: shutdown
java.lang.RuntimeException: Exception in Preloader start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$156(LauncherImpl.java)
at com.sun.javafx.application.LauncherImpl$$Lambda$2.run(Unknown Source)
at java.lang.Thread.run(Thread.java)
Caused by: java.lang.NullPointerException
at com.gluonhq.charm.down.plugins.ios.IOSOrientationService.getOrientation(IOSOrientationService.java)
at my.app.Preloader.lambda$start$24(Preloader.java)
at my.app.Preloader$$Lambda$3.accept(Unknown Source)
at java.util.Optional.ifPresent(Optional.java)
at my.app.Preloader.start(Preloader.java)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java)
at com.sun.javafx.application.LauncherImpl$$Lambda$7.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(PlatformImpl.java)
at com.sun.javafx.application.PlatformImpl$$Lambda$7.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java)
at com.sun.javafx.application.PlatformImpl$$Lambda$19.run(Unknown Source)
at java.security.AccessController.doPrivileged(AccessController.java)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformImpl.java)
at com.sun.javafx.application.PlatformImpl$$Lambda$6.run(Unknown Source)
at org.robovm.apple.uikit.UIApplication.main(UIApplication.java)
at org.robovm.apple.uikit.UIApplication.main(UIApplication.java)
at org.javafxports.jfxmobile.ios.BasicLauncher.main(BasicLauncher.java)
望着code,我认为有可能是只有一个问题原因:
@Override
public final Optional<Orientation> getOrientation() {
switch (orientationText) {
case "Portrait":
case "PortraitUpsideDown":
return Optional.of(Orientation.VERTICAL);
case "LandscapeLeft":
case "LandscapeRight":
return Optional.of(Orientation.HORIZONTAL);
case "Unknown":
default:
return Optional.empty();
}
}
我的猜测是,orientationText
是null
,因此崩溃。我想这个行2017-02-06 10:43:37.104693 MyApp[447:282589] Orientation is Unknown
有助于这一点。
这是一个错误?有什么办法可以绕过这个吗? (例如,有一些的建立需要在iOS上,像Android上的许可制度?)
在此先感谢和问候,
丹尼尔
#edit:的onOrientationChange
方法是不是很复杂:
private void onOrientationChange(ObservableValue<? extends Orientation> obs, Orientation o, Orientation n) {
if (n == null || splashPane == null)
return;
splashPane.pseudoClassStateChanged(vertical, Orientation.VERTICAL == n);
splashPane.pseudoClassStateChanged(horizontal, Orientation.HORIZONTAL == n);
}
所以我想这将足以将代码更新为某事。像这样
Services.get(OrientationService.class).ifPresent(service -> {
service.orientationProperty()。addListener(this :: onOrientationChange); });
(它的工作在Android上,所以我也可以检查平台,只有做到这一点对非IOS左右)
鉴于日志给出了非空方向,我不认为'orientationText'为空。你能修改你的事件处理程序吗?现在不要使用'onOrientationChange'。只需打印方向新值:'service.orientationProperty()。addListener((obs,ov,nv) - > System.out.println(“O:”+ nv));'看看它是否失败。 –
我用'onOrientationChange'的内容更新了我的问题(见底部) - 但是,我可以试试。午餐后会给你结果,好吗? – dzim