android - Gluon 移动 View 在 Android 上崩溃

标签 android javafx gluon-mobile

我正在使用 Gluon Mobile 开发应用程序.最近我用 Presenter 创建了一个新 View ,将它添加到 AppViewManager.class,并且一切都在 Windows 上工作(当我使用“运行”gradle 构建脚本时)。但是当我在我的 Android 手机(Oppo,Android 8.1)上运行一个应用程序时,它会在切换到从另一个 View 触发的新 View 后崩溃:

private void showDomainInfo(TaskDomainModel task) {
    System.out.println("CYBER_ESSENTIALS | going to start DOMAIN_VIEW...");
    getApp().LastDomainModel = task;
    AppViewManager.DOMAIN_VIEW.switchView();
}

应用程序崩溃,logcat 中没有任何有用的信息:

12-12 16:12:43.537  1528  1528 E FXEntity: call native MultitouchEvent, density = 2.0, touchXs0 = 348
12-12 16:12:43.609  1528  1561 I GLASS   : Call InternalSurfaceView_onMultiTouchEventNative
12-12 16:12:43.609  1528  1561 I GLASS   : Glass will pass multitouchevent to monocle with count = 1
12-12 16:12:43.609  1528  1561 I System.out: don't add points, primary = -1
12-12 16:12:43.641  1528  1561 I System.out: CYBER_ESSENTIALS | going to start DOMAIN_VIEW...
12-12 16:12:43.660  2063  4143 W ActivityManager:   Force finishing activity com.CyberEssentials/javafxports.android.FXActivity
12-12 16:12:43.669  1528  1528 V FXActivity: onPause
12-12 16:12:43.671  2063  2130 V WindowManager: reevaluateVisibility focusApp:AppWindowToken{12a47ed token=Token{4dcd53c ActivityRecord{fb1db2f u0 com.CyberEssentials/javafxports.android.FXActivity t4771}}}
12-12 16:12:43.682  2063  4887 D ActivityTrigger: activityResumeTrigger: The activity in ApplicationInfo{cadb841 com.oppo.launcher} is now in focus and seems to be in full-screen mode
12-12 16:12:43.682  2063  4887 E ActivityTrigger: activityResumeTrigger: not whiteListedcom.oppo.launcher/com.oppo.launcher.Launcher/3
12-12 16:12:43.687  2063  4887 V WindowManager: Changing focus from Window{7cffb2b u0 com.CyberEssentials/javafxports.android.FXActivity} to null
12-12 16:12:43.690  2063  4887 D ActivityManager: zjm TOP_APP is ProcessRecord{345b1a2 22728:com.oppo.launcher/u0a20} uid is 10020
12-12 16:12:43.701  2063  2130 V WindowManager: reevaluateVisibility focusApp:AppWindowToken{4a759ed token=Token{a1e0328 ActivityRecord{f1c9d4b u0 com.oppo.launcher/.Launcher t4240}}}
12-12 16:12:43.708  1528  1561 I Process : Sending signal. PID: 1528 SIG: 9

这是我针对此问题 View 的 Presenter 类:

package com.CyberEssentials.views;

import com.CyberEssentials.CEApplication;
import com.gluonhq.charm.glisten.afterburner.GluonPresenter;
import com.gluonhq.charm.glisten.animation.BounceInRightTransition;
import com.gluonhq.charm.glisten.control.AppBar;
import com.gluonhq.charm.glisten.control.CardPane;
import com.gluonhq.charm.glisten.mvc.View;
import com.gluonhq.charm.glisten.visual.MaterialDesignIcon;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

public class DomainDetailsPresenter extends GluonPresenter<CEApplication> {

    @FXML
    public Label domainInfoText;
    @FXML
    public TextField cmsDetails;
    @FXML
    public TextField categoryDetails;
    @FXML
    public TextField sslDetails;
    @FXML
    public CardPane subdomainsCardPane;
    @FXML
    public TextArea nmapScanText;
    @FXML
    public TextArea whoisDetails;
    @FXML
    public CardPane dnsReplCardPane;
    @FXML
    private View domainDetails;

    public void initialize() {
        domainDetails.setShowTransitionFactory(BounceInRightTransition::new);

        domainDetails.showingProperty().addListener((obs, oldValue, newValue) -> {
            if (newValue) {
                AppBar appBar = getApp().getAppBar();
                appBar.setNavIcon(MaterialDesignIcon.ARROW_BACK.button(e ->
                        AppViewManager.DASHBOARD_VIEW.switchView()
                ));
                appBar.setTitleText(getApp().LastDomainModel.getDomain());
                appBar.getActionItems().add(MaterialDesignIcon.SHARE.button(e ->
                        System.out.println("Share")));
                initVars();
            }
        });
    }

    private void initVars() {
        domainInfoText.setText("Report for " + getApp().LastDomainModel.getCreated());

        String cms = getApp().LastDomainModel.getCms();
        if (cms.equalsIgnoreCase("")) cms = "Unrecognized / none";
        cmsDetails.setText(cms);

        categoryDetails.setText(getApp().LastDomainModel.getCategory());

        subdomainsCardPane.getItems().addAll(getApp().LastDomainModel.getSubdomains());

        nmapScanText.setText(getApp().LastDomainModel.getNmap());
        whoisDetails.setText(getApp().LastDomainModel.getWhois());
    }

}

和fxml文件:

<?xml version="1.0" encoding="UTF-8"?>

<!--
    Copyright (c) 2017, Gluon and/or its affiliates.
    All rights reserved. Use is subject to license terms.

    This file is available and licensed under the following license:

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:

   - Redistributions of source code must retain the above copyright
     notice, this list of conditions and the following disclaimer.
   - Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in
     the documentation and/or other materials provided with the distribution.
   - Neither the name of Oracle Corporation and Gluon nor the names of its
     contributors may be used to endorse or promote products derived
     from this software without specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->

<?import com.gluonhq.charm.glisten.control.CardPane?>
<?import com.gluonhq.charm.glisten.mvc.View?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<View xmlns:fx="http://javafx.com/fxml/1" fx:id="domainDetails" maxHeight="-Infinity" maxWidth="-Infinity"
      minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="335.0"
      xmlns="http://javafx.com/javafx/8.0.0" fx:controller="com.CyberEssentials.views.DomainDetailsPresenter">
    <center>
        <CardPane BorderPane.alignment="CENTER">
            <items>
                <Label fx:id="domainInfoText" alignment="CENTER" text="\\%s domain information" textAlignment="CENTER"
                       wrapText="true">
                    <padding>
                        <Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
                    </padding>
                </Label>
                <TitledPane animated="false" text="Basic info">
                    <content>
                        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
                            <children>
                                <TextField editable="false" layoutX="2.0" layoutY="1.0" prefHeight="26.0"
                                           prefWidth="313.0" promptText="A content management system (CMS) :"/>
                                <TextField fx:id="cmsDetails" layoutX="4.0" layoutY="27.0" prefHeight="26.0"
                                           prefWidth="308.0" text="WordPress 4.4.2"/>
                                <TextField editable="false" layoutX="6.0" layoutY="53.0" prefHeight="26.0"
                                           prefWidth="304.0" promptText="Categories:"/>
                                <TextField fx:id="categoryDetails" layoutX="5.0" layoutY="77.0" prefHeight="26.0"
                                           prefWidth="308.0" text="gambling,sports"/>
                                <TextField editable="false" layoutX="6.0" layoutY="103.0" prefHeight="26.0"
                                           prefWidth="304.0" promptText="SSL / TLS:"/>
                                <TextField fx:id="sslDetails" layoutX="6.0" layoutY="129.0" prefHeight="26.0"
                                           prefWidth="305.0" text="Under developement"/>
                            </children>
                        </AnchorPane>
                    </content>
                </TitledPane>
                <TitledPane animated="false" expanded="false" text="Subdomains">
                    <content>
                        <AnchorPane minHeight="-Infinity" minWidth="-Infinity" prefHeight="202.0" prefWidth="291.0">
                            <children>
                                <CardPane fx:id="subdomainsCardPane" maxHeight="-Infinity" maxWidth="-Infinity"
                                          minHeight="-Infinity" minWidth="-Infinity" prefHeight="203.0"
                                          prefWidth="317.0">
                                    <items>
                                    </items>
                                </CardPane>
                            </children>
                        </AnchorPane>
                    </content>
                </TitledPane>
                <TitledPane animated="false" expanded="false" text="NMAP scan">
                    <content>
                        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
                            <children>
                                <TextArea fx:id="nmapScanText" layoutY="3.0" prefHeight="177.0" prefWidth="316.0"
                                          promptText="Gluon Mobile is priced per developer with no royalties or hidden fees. Regardless of which tier you use (including the free tier), you will have everything you need to build great looking Android and iOS applications that are ready (and able) to be deployed into the appropriate app stores."/>
                            </children>
                        </AnchorPane>
                    </content>
                </TitledPane>
                <TitledPane animated="false" expanded="false" text="Whois Lookup">
                    <content>
                        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
                            <children>
                                <TextArea fx:id="whoisDetails" layoutY="3.0" prefHeight="177.0" prefWidth="316.0"
                                          promptText="Gluon Mobile is priced per developer with no royalties or hidden fees. Regardless of which tier you use (including the free tier), you will have everything you need to build great looking Android and iOS applications that are ready (and able) to be deployed into the appropriate app stores."/>
                            </children>
                        </AnchorPane>
                    </content>
                </TitledPane>
                <TitledPane animated="false" expanded="false" text="Passive DNS Replication">
                    <content>
                        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
                            <children>
                                <CardPane fx:id="dnsReplCardPane" prefHeight="180.0" prefWidth="318.0">
                                    <items>
                                    </items>
                                </CardPane>
                            </children>
                        </AnchorPane>
                    </content>
                </TitledPane>
                <TextArea editable="false" prefHeight="79.0" prefWidth="319.0"
                          promptText="All the data provided by third party services, such as www.virustotal.com, api.hackertarget.com, Avast.com, whatcms.org."
                          text="All the data provided by third party services, such as www.virustotal.com, api.hackertarget.com, Avast.com, whatcms.org."
                          wrapText="true"/>
            </items>
        </CardPane>
    </center>
</View>

IDK 如果那是一些与 Android 相关的问题,但它真的很奇怪。 期待您的帮助。

最佳答案

好了,问题解决了。 我按照 @josé-pereda 的建议用 try/catch 覆盖了代码

try {
    AppViewManager.DOMAIN_VIEW.switchView();
} catch (Exception e) {
    System.out.println("CYBER_ESSENTIALS | " + e);
}

并得到一个异常(exception):

java.lang.IllegalStateException: Cannot load com/CyberEssentials/views/domaindetails.fxml

这帮助我找到了这个答案 NullPointerException load fxml

它没有解决我的问题,但我开始研究我的 fxml 文件名和它的变量名。看起来 fxml 加载器不太喜欢文件名中的驼峰式大小写。

新 View 现在可用。

关于android - Gluon 移动 View 在 Android 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53739822/

相关文章:

android - 如何注入(inject)应用程序 : Context in ViewModel with Hilt?

Android AsyncTask 通过 http Post 发送数据

JavaFXPorts:未选择 ListView 中的选定项目

javafx - 任务 'run' 导致 : org. joor.ReflectException : java. lang.NoSuchFieldException: javaExecHandleBuilder - Gluon 移动项目

android - 如何以编程方式获得强调色?

java - Android Studio无法识别 "setAdapter()"方法

JavaFX 延迟绘制形状

java - Spring Boot从2.1.9升级到2.2后出现InaccessibleObjectException

java - 如何在 JavaFX 中实现节点的选择

android - 使用 gluon-mobile API 以编程方式打开/关闭 Android 中的 Wifi