こんばんは。
今回は、画面表示ができなくなるという現象が起きてしまったので質問させていただきたいです。
いつも、聞いてばかりで申し訳ないと思い、
http://stackoverflow.com/questions/25183064/java-fxml-load-exception
http://stackoverflow.com/questions/22914895/fxml-load-exception
このような、類似してそうなサイトをいくつも見てみましたが、参考になりそうなのを見つけることはできませんでした。
この解決法とともにこの解決法に近づくことができそうなググり方なども教えていただけるとありがたいです。
ググる能力がすごく足りないので。。。
僕は、エラー名を使ってググりました。
コンソールのエラー文 ↓
javafx.fxml.LoadException:
/Users/TakahitoNakashima/JavaWorkspace/App02/bin/application/Window.fxml
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2543) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097) at application.Main.start(Main.java:14) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163(LauncherImpl.java:863) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(PlatformImpl.java:326) at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformImpl.java:294) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[3,3]
Message: 処理命令の先頭にはターゲットの名前が必要です。
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:601)
at javax.xml.stream.util.StreamReaderDelegate.next(StreamReaderDelegate.java:88)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2513)
... 14 more
Main.java ↓
package application;
import javafx.fxml.FXMLLoader;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
BorderPane root = (BorderPane) FXMLLoader.load(getClass().getResource("Window.fxml"));
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
BorderPane roots = new BorderPane(); Stage stage2 = new Stage(); stage2.initOwner(primaryStage); stage2.setScene(new Scene(new BorderPane(), 640d, 400d)); Scene scene2 = new Scene(roots,500,500); stage2.setScene(scene2); stage2.show(); stage2.setX(primaryStage.getX() + 100); stage2.setY(primaryStage.getY() + 100); } catch(Exception e) { e.printStackTrace(); } } public static void main(String[] args) { launch(args); }
}
Window.fxml ↓
<?xml version="1.0" encoding="UTF-8"?><? import javafx.scene.label ?>
<BorderPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8">
<top> <Label fx:id="label1" text="This is FXML! /> </top> </BorderPane>追記:
BorderPane root = (BorderPane) FXMLLoader.load(getClass().getResource("Window.fxml"));
を変更した時にエラーが出るようになりました。
もともと、
BorderPane roots = new BorderPane();
だったですが、この時にはwindowが2つ出ました。
