我正在使用Gluon Mobile开发一个应用程序。最近,我用presenter创建了一个新视图,并将其添加到AppViewManager.class,并且所有内容都在Windows上运行(当我使用“运行” gradle构建脚本时)。但是,当我在Android手机(Oppo,Android 8.1)上运行应用程序时,从另一个视图触发切换到新视图后,它会崩溃:
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
这是我针对此问题视图的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相关的问题,那确实很奇怪。 期待您的帮助。
答案 0 :(得分:1)
好的,问题解决了。 我按照@josé-pereda的建议使用try / catch覆盖了代码
try {
AppViewManager.DOMAIN_VIEW.switchView();
} catch (Exception e) {
System.out.println("CYBER_ESSENTIALS | " + e);
}
有一个例外:
java.lang.IllegalStateException: Cannot load com/CyberEssentials/views/domaindetails.fxml
这帮助我找到了这个答案NullPointerException load fxml
它没有解决我的问题,但是我开始使用我的fxml文件名和它的变量名。看起来fxml loader真的不喜欢文件名中的驼峰式大小写。
新视图正在运行。