diff --git a/src/main/java/cn/reddragon/eportal/config/ConfigManager.java b/src/main/java/cn/reddragon/eportal/config/ConfigManager.java index 28b2c85..6989c5c 100644 --- a/src/main/java/cn/reddragon/eportal/config/ConfigManager.java +++ b/src/main/java/cn/reddragon/eportal/config/ConfigManager.java @@ -48,18 +48,27 @@ public static void loadConfigs() { alert.setContentText("配置文件版本过旧! 这可能导致配置加载错误. 由于软件会在退出时保存配置文件, 请考虑在软件退出前备份旧版配置文件."); alert.showAndWait(); } - for (AbstractConfig config : configs) { - if (config.name.equals(next.getKey())) { - config.fromJson(next.getValue()); - logger.info("成功加载配置文件 {}.", config.name); - break; + AbstractConfig config = null; + try { + for (AbstractConfig abstractConfig : configs) { + config = abstractConfig; + if (config.name.equals(next.getKey())) { + config.fromJson(next.getValue()); + logger.info("成功加载配置文件 {}.", config.name); + break; + } } + } catch (Exception e) { + logger.error("加载配置文件 {} 时发生错误!", config.name); + logger.error(e); } } } else { logger.warn("配置文件损坏!"); } } catch (FileNotFoundException e) { + logger.error("无法加载配置文件!"); + logger.error(e); throw new RuntimeException(e); } } diff --git a/src/main/java/cn/reddragon/eportal/config/configs/AccountConfig.java b/src/main/java/cn/reddragon/eportal/config/configs/AccountConfig.java index 1623f21..518a165 100644 --- a/src/main/java/cn/reddragon/eportal/config/configs/AccountConfig.java +++ b/src/main/java/cn/reddragon/eportal/config/configs/AccountConfig.java @@ -9,7 +9,8 @@ import com.google.gson.JsonObject; public class AccountConfig extends AbstractConfig { - public static int index; + public static int index = -1; + public AccountConfig() { super("Account"); } diff --git a/src/main/java/cn/reddragon/eportal/config/configs/NetTypeConfig.java b/src/main/java/cn/reddragon/eportal/config/configs/NetTypeConfig.java index b15456d..abda053 100644 --- a/src/main/java/cn/reddragon/eportal/config/configs/NetTypeConfig.java +++ b/src/main/java/cn/reddragon/eportal/config/configs/NetTypeConfig.java @@ -6,7 +6,7 @@ import com.google.gson.JsonPrimitive; public class NetTypeConfig extends AbstractConfig { - public static int index; + public static int index = -1; public NetTypeConfig() { super("NetType"); diff --git a/src/main/java/cn/reddragon/eportal/window/MainWindow.java b/src/main/java/cn/reddragon/eportal/window/MainWindow.java index d00d7ab..ff09ae1 100644 --- a/src/main/java/cn/reddragon/eportal/window/MainWindow.java +++ b/src/main/java/cn/reddragon/eportal/window/MainWindow.java @@ -78,7 +78,7 @@ public void start(Stage stage) throws IOException { box.setValue(box.getItems().get(NetTypeConfig.index)); else box.setValue(""); - if (AccountConfig.index < AccountManager.accounts.size()) + if (AccountConfig.index < AccountManager.accounts.size() && AccountConfig.index != -1) box2.setValue(box2.getItems().get(AccountConfig.index)); /* TextField name = (TextField) root.lookup("#userNameField");