gpt4 book ai didi

java - 在 javafxports android 项目中查找配置文件时出现问题

转载 作者:行者123 更新时间:2023-12-02 12:44:04 25 4
gpt4 key购买 nike

我正在尝试使用 javafxports 从 javaFX 项目构建 Android 应用程序。目前,我在移动设备上安装并启动它时遇到问题,它抛出 ConfigurationException。 enter image description here这是使用该文件的代码:

public class AppConfig extends XMLConfiguration {

/**
*
*/
private static final long serialVersionUID = 550015250032006413L;
private static AppConfig instance;
private static String configFile = "src/main/assets/config.xml";

// Singleton initialiser
static {
instance = new AppConfig(configFile);
}

/**
* Constructor
*
* @param fileName Configuration file name.
*/
private AppConfig(String fileName) {
init(fileName);
}

/**
* Initialize the class.
*
* @param fileName Configuration file name.
*/
private void init(String fileName) {
setFileName(fileName);
try {
load();
} catch (ConfigurationException configEx) {
configEx.printStackTrace();
}
}

这是 gradle 文件:

    apply plugin: 'org.javafxports.jfxmobile'



buildscript {
repositories {
jcenter()
maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases' }
}

dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.3.5'
}
}



repositories {
jcenter()
maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
}

mainClassName = "com.example.amladzhov.irisandroid.sample.Client.StartApplication"

jfxmobile {
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}

dependencies {

compile 'commons-configuration:commons-configuration:1.6'
compile 'org.apache.commons:commons-exec:1.3'
compile 'commons-discovery:commons-discovery:0.5'
compile 'org.apache.axis:axis:1.4'
compile 'javax.xml.rpc:javax.xml.rpc-api:1.1.1'
//compile 'wsdl4j:wsdl4j:1.6.2'
compile 'org.jdom:jdom:2.0.2'
compile 'com.google.code.ksoap2-android:ksoap2-android:3.6.1'
compile group: 'commons-beanutils', name: 'commons-beanutils', version: '1.9.3'
}
}
}

该文件位于

src/main/assets/config.xml

最佳答案

您不能期望 xml 文件会在运行时放置在 src 文件夹下。

但请注意,main 包下的 assets 文件夹不会导出到 Android,因此该文件将无法以任何方式使用。

虽然有一个 src/android/assets 文件夹可用于放置 Android 所需的资源,但需要 Android API 来读取它。

最好的选择是将 xml 文件放在 src/main/resources 下,然后像在 Java 中经常使用 getResources()< 一样加载该文件.

因此,将该文件放在 src/main/resources/config.xml 下,并替换为:

private static String configFile = "src/main/assets/config.xml";

这样:

private static String configFile = AppConfig.class.getResources("/config.xml").toExternalForm();

关于java - 在 javafxports android 项目中查找配置文件时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44845996/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com