我之前创建了一个JavaFx程序,起初工作得非常好,但是经过一段时间后,当我想启动程序时,我总是会遇到这个错误。 Bug如下:
Main (4) [Java Application]
application.Main at localhost:49308
Thread [main] (Suspended (exception NullPointerException))
SystemProperties.setVersions() line: not available
SystemProperties.lambda$static$28() line: not available
762152757.run() line: not available
AccessController.doPrivileged(PrivilegedAction<T>) line: not available [native method]
SystemProperties.<clinit>() line: not available
LauncherImpl.startToolkit() line: not available
LauncherImpl.launchApplicationWithArgs(String, String, String[]) line: not available
LauncherImpl.launchApplication(String, String, String[]) line: not available
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
NativeMethodAccessorImpl.invoke(Object, Object[]) line: not available
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available
Method.invoke(Object, Object...) line: not available
LauncherHelper$FXHelper.main(String...) line: not available
C:\Program Files\Java\jre1.8.0_60\bin\javaw.exe (20.01.2016, 17:38:44)
代码:
主要课程
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
Reader.setLanguageStrings();
Parent root = FXMLLoader.load(getClass().getResource("Main_AnchorPane.fxml"));
Scene scene = new Scene(root,960,740);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.centerOnScreen();
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
读者课程:
package application;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Locale;
public class Reader {
private static Locale user_language = Locale.getDefault();
private static CharSequence language_identifier;
private static String language = getLanguage();
@SuppressWarnings("resource")
public static void setLanguageStrings() {
switch (language) {
case "Deutsch":
try {
BufferedReader reader = new BufferedReader(new FileReader(new File("Deutsch")));
UI_Strings.Text_Stage = reader.readLine();
UI_Strings.Text_Project_Menu = reader.readLine();
UI_Strings.Text_New_Project_MenuItem = reader.readLine();
UI_Strings.Text_Open_Project_MenuItem = reader.readLine();
UI_Strings.Text_Resourcepacks_Menu = reader.readLine();
UI_Strings.Text_Import_Resourcepacks_MenuItem = reader.readLine();
UI_Strings.Text_Manage_Resourcepacks_MenuItem = reader.readLine();
} catch (Exception e) {
e.printStackTrace();
}
break;
case "Englisch":
try {
BufferedReader reader = new BufferedReader(new FileReader(new File("Englisch")));
UI_Strings.Text_Stage = reader.readLine();
UI_Strings.Text_Project_Menu = reader.readLine();
UI_Strings.Text_New_Project_MenuItem = reader.readLine();
UI_Strings.Text_Open_Project_MenuItem = reader.readLine();
UI_Strings.Text_Resourcepacks_Menu = reader.readLine();
UI_Strings.Text_Import_Resourcepacks_MenuItem = reader.readLine();
UI_Strings.Text_Manage_Resourcepacks_MenuItem = reader.readLine();
} catch (Exception e) {
e.printStackTrace();
}
break;
}
}
private static String getLanguage() {
language_identifier = "en";
if(user_language.getLanguage().contains(language_identifier)) {
return ("Englisch");
}
language_identifier = "de";
if(user_language.getLanguage().contains(language_identifier)) {
return("Deutsch");
}
return("Englisch");
}
}
在类中,UI_Strings只是对字符串的一些deaclaration。
Main_AnchorPane.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.SplitPane?>
<AnchorPane fx:id="Main_AnchorPane" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
<children>
<SplitPane fx:id="Main_SplitPane"
dividerPositions="0.6178861788617886" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" orientation="VERTICAL" prefHeight="740.0" prefWidth="960.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="25.0">
<items>
<SplitPane fx:id="Upper_SplitPane" dividerPositions="0.36116910229645094" prefHeight="160.0" prefWidth="200.0">
<items>
<TreeView fx:id="tree_navigation" prefHeight="200.0" prefWidth="200.0" />
<AnchorPane fx:id="right_AnchorPane" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" />
</items>
</SplitPane>
<AnchorPane fx:id="lower_AnchorPane" minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0" />
</items>
</SplitPane>
<MenuBar fx:id="MenuBar" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<menus>
<Menu fx:id="Project_Menu" mnemonicParsing="false">
<items>
<MenuItem fx:id="New_Project_MenuIttem" mnemonicParsing="false" />
<SeparatorMenuItem fx:id="Seperator_1_SeperastorMenuItem" mnemonicParsing="false" />
<MenuItem fx:id="Open_Project_MenuItem" mnemonicParsing="false" />
</items>
</Menu>
<Menu fx:id="Resourcepacks_Menu" mnemonicParsing="false">
<items>
<MenuItem fx:id="Import_Rescourcepacks_MenuItem" mnemonicParsing="false" />
<MenuItem fx:id="Mangae_Resourcepacks_MenuItem" mnemonicParsing="false" />
</items>
</Menu>
</menus>
</MenuBar>
这只是错误,我知道之前已经问过类似的问题(JavaFX NullPointerException in SystemProperties.setVersions()),但我想问一下,如果有人知道这个bug的解决方法。
提前致谢!
我使用的是windows7 64bit,java 8u60