使用Maven

时间:2019-08-19 11:48:35

标签: maven javafx netbeans-8

当我尝试在NetBeans中运行应用程序时,出现异常,提示Exception in Application start method java.lang.reflect.InvocationTargetException 我知道这是一个在这里经常问到的问题,但似乎没有一个问题和答案有效。我尝试了其中的几个,例如,将fxml文件的目录从src/main/java/更改为src/main/resources

这是我的主要课程代码:

package com.zarja.offlinestudio;

import com.zarja.offlinestudio.util.settings.SettingsUtil;
import com.zarja.offlinestudio.util.log.LogUtil;
import com.zarja.offlinestudio.view.util.SceneManager;
import javafx.application.Application;
import javafx.stage.Stage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class OfflineStudioGUI extends Application {

    private static final String CLASS_NAME = OfflineStudioGUI.class.getCanonicalName();
    private static final Logger LOGGER = LoggerFactory.getLogger(CLASS_NAME);

    @Override
    public void start(Stage stage) throws Exception {        
        LogUtil.init();
        SettingsUtil.init();
        SceneManager.init(stage);

        //UserManager.getInstance();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

我的SettingsUtil类(这是发生异常的地方)

package com.zarja.offlinestudio.util.settings;

//import com.zarja.offlinestudio.util.oldCode.DataManager;
import com.zarja.offlinestudio.util.log.LogMessages;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//import java.util.logging.Level;
//import java.util.logging.Logger;

public class SettingsUtil {

    private static final String CLASS_NAME = SettingsUtil.class.getCanonicalName();
    private static final Logger LOGGER = LoggerFactory.getLogger(CLASS_NAME);
    private static final Properties SETTINGS = new Properties();
    private static final String FILE_NAME = "settings.txt";

    public static void init() { //loadSettings
        try {
            SETTINGS.load(new FileInputStream(FILE_NAME));
        } catch (FileNotFoundException ex) {
            resetToDefaultProperties();
            //LOGGER.log(Level.INFO, "File {1} was not found, so one was created", FILE_NAME);
            LOGGER.info(LogMessages.get(LogMessages.SETTINGS_UTIL.INFO.LOAD), FILE_NAME);
            saveSettings();
        } catch (IOException ex) {
            //LOGGER.log(Level.SEVERE, "Problem with file input stream", ex);
            LOGGER.error(LogMessages.get(LogMessages.SETTINGS_UTIL.SEVERE.LOAD), ex);
        }
    }

    public static void saveSettings() {
        try {
            SETTINGS.store(new FileOutputStream(FILE_NAME), CLASS_NAME);
        } catch (FileNotFoundException ex) {
            //LOGGER.log(Level.SEVERE, "File not found", ex);            
            LOGGER.error(LogMessages.get(LogMessages.SETTINGS_UTIL.SEVERE.SAVE_FNF), ex);            
        } catch (IOException ex) {
            //LOGGER.log(Level.SEVERE, "Problem with file output stream", ex);
            LOGGER.error(LogMessages.get(LogMessages.SETTINGS_UTIL.SEVERE.SAVE_OS), ex);
        }
    }

    public static void resetToDefaultProperties() {
        setMap(App.getDefaultConfig());
    }

    public static Map<String, String> getMap() {
        TreeMap<String, String> treeMap = new TreeMap<>();
        for(final String key: SETTINGS.stringPropertyNames()) {
            treeMap.put(key, SETTINGS.getProperty(key));
        }
        return treeMap;
    }

    public static void setMap(Map<String, String> map) {
        SETTINGS.clear();
        SETTINGS.putAll(map);
    }

    public static String get(String propertyName) {
        return SETTINGS.getProperty(propertyName);
    }

    public static void set(String propertyName, String propertyValue) {
        SETTINGS.setProperty(propertyName, propertyValue);
    }

}

StackTrace:

Exception in Application start method
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
    at java.util.Hashtable.put(Hashtable.java:460)
    at java.util.Hashtable.putAll(Hashtable.java:524)
    at com.zarja.offlinestudio.util.settings.SettingsUtil.setMap(SettingsUtil.java:64)
    at com.zarja.offlinestudio.util.settings.SettingsUtil.resetToDefaultProperties(SettingsUtil.java:51)
    at com.zarja.offlinestudio.util.settings.SettingsUtil.init(SettingsUtil.java:28)
    at com.zarja.offlinestudio.OfflineStudioGUI.start(OfflineStudioGUI.java:19)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
    ... 1 more
Exception running application com.zarja.offlinestudio.OfflineStudioGUI

我仔细查看了堆栈跟踪,但是我无法弄清问题所在。

0 个答案:

没有答案