加载一个

时间:2016-03-11 11:48:06

标签: java javafx fxml fxmlloader

当我点击主页的“开始”按钮时,我正在主页中间加载SimulatorWindow.fxml文件。

This is the SimulatorWindow.fxml file.

在这里进入给定图像的红色标记区域,我需要加载另一个fxml文件(名为Simulator.fxml)。

这是我的SimulatorWindowController.java文件

package SortingAlgorithmSimulator.view;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import SortingAlgorithmSimulator.Main;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextArea;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class SimulatorWindowController extends Application
{
    private HomeController hc=new HomeController();
    @FXML
    private TextArea AlgorithmField;
    @FXML
    private CheckBox screenSize;
    @FXML
    public static BorderPane simu;
    @FXML
    private void initialize() throws IOException
    {   FXMLLoader loader1=new FXMLLoader();
        loader1.setLocation(Main.class.getResource("view/Simulator.fxml"));
        BorderPane mainItems1=loader1.load();
        simu.setCenter(mainItems1);
        BufferedReader buff = null;
          try {
               buff = new BufferedReader(new FileReader(hc.selectedFile));
               String str;
               while ((str = buff.readLine()) != null)
               {
                   AlgorithmField.appendText(str+"\n");
               }
         } catch (IOException e)
          {
          } finally
          {
            try { buff.close(); } catch (Exception ex) { }
          }
    }
    @FXML
    private void goHome() throws IOException
    {
        Main.showHome();
    }
    @FXML
    private void goHelp() throws IOException
    {
        Main.showHelp();
    }
    @FXML
    private void goAboutMe() throws IOException
    {
        Main.showAboutMe();
    }
    @FXML
    private void goScreen() throws IOException
    {
        if(screenSize.isSelected())
        {
            Main.primaryStage.setFullScreen(true);
            screenSize.setText("Exit Full Screen");
        }
        else 
        {
            Main.primaryStage.setFullScreen(false); 
            screenSize.setText("Full Screen");
        }
    }
    @FXML
    private void goExit() throws IOException
    {
        System.exit(0);
    }
    @Override
    public void start(Stage arg0) throws Exception
    {
        // TODO Auto-generated method stub
    }
}

但是当我运行此代码时,它显示错误NullPointerException。

以下是错误报告

  
    

线程中的异常" JavaFX应用程序线程"了java.lang.RuntimeException:     java.lang.reflect.InvocationTargetException at     javafx.fxml.FXMLLoader $ MethodHandler.invoke(未知来源)at at     javafx.fxml.FXMLLoader $ ControllerMethodEventHandler.handle(未知     来源)at     com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(未知     来源)at     com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(未知     来源)at     com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(未知     来源)at     com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(未知     来源)at     com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(未知     来源)at     com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(未知     来源)at     com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(未知     来源)at     com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(未知     来源)at     com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(未知     来源)at     com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(未知     来源)com.sun.javafx.event.EventUtil.fireEventImpl(未知     来源)com.sun.javafx.event.EventUtil.fireEvent(未知来源)       在javafx.event.Event.fireEvent(未知来源)at     javafx.scene.Node.fireEvent(未知来源)at     javafx.scene.control.Button.fire(未知来源)at     com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(未知     来源)at     com.sun.javafx.scene.control.skin.BehaviorSkinBase $ 1.handle(未知     来源)at     com.sun.javafx.scene.control.skin.BehaviorSkinBase $ 1.handle(未知     来源)at     com.sun.javafx.event.CompositeEventHandler $ NormalEventHandlerRecord.handleBubblingEvent(未知     来源)at     com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(未知     来源)at     com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(未知     来源)at     com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(未知     来源)at     com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(未知     来源)at     com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(未知     来源)at     com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(未知     来源)at     com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(未知     来源)at     com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(未知     来源)at     com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(未知     来源)at     com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(未知     来源)com.sun.javafx.event.EventUtil.fireEventImpl(未知     来源)com.sun.javafx.event.EventUtil.fireEvent(未知来源)       在javafx.event.Event.fireEvent(未知来源)at     javafx.scene.Scene $ MouseHandler.process(未知来源)at     javafx.scene.Scene $ MouseHandler.access $ 1500(未知来源)at     javafx.scene.Scene.impl_processMouseEvent(未知来源)at     javafx.scene.Scene $ ScenePeerListener.mouseEvent(未知来源)at     com.sun.javafx.tk.quantum.GlassViewEventHandler $ MouseEventNotification.run(未知     来源)at     com.sun.javafx.tk.quantum.GlassViewEventHandler $ MouseEventNotification.run(未知     来自java.security.AccessController.doPrivileged(Native Method)       在     com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda $ handleMouseEvent $ 354(未知     来源)at     com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(未知     来源)at     com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(未知     来自)com.sun.glass.ui.View.handleMouseEvent(未知来源)at     com.sun.glass.ui.View.notifyMouse(未知来源)at     com.sun.glass.ui.win.WinApplication._runLoop(Native Method)at     com.sun.glass.ui.win.WinApplication.lambda $ null $ 148(未知来源)       在java.lang.Thread.run(未知来源)引起:     java.lang.reflect.InvocationTargetException at     sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at     sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)at     sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)at     java.lang.reflect.Method.invoke(未知来源)at     sun.reflect.misc.Trampoline.invoke(未知来源)at     sun.reflect.GeneratedMethodAccessor1.invoke(未知来源)at     sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)at     java.lang.reflect.Method.invoke(未知来源)at     sun.reflect.misc.MethodUtil.invoke(Unknown Source)... 49更多引起     by:javafx.fxml.LoadException:     /D:/Document%20Files/Java%20Programming/bin/SortingAlgorithmSimulator/view/SimulatorWindow.fxml

         

at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)at at     javafx.fxml.FXMLLoader.loadImpl(未知来源)at     javafx.fxml.FXMLLoader.load(未知来源)at     SortingAlgorithmSimulator.Main.showSimulatorWindow(Main.java:87)at     SortingAlgorithmSimulator.view.HomeController.goSimulatorWindow(HomeController.java:64)       ... 58更多引起:java.lang.reflect.InvocationTargetException       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at     sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)at     sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)at     java.lang.reflect.Method.invoke(未知来源)at     sun.reflect.misc.Trampoline.invoke(未知来源)at     sun.reflect.GeneratedMethodAccessor1.invoke(未知来源)at     sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)at     java.lang.reflect.Method.invoke(未知来源)at     sun.reflect.misc.MethodUtil.invoke(Unknown Source)... 63更多引起     by:java.lang.NullPointerException at     SortingAlgorithmSimulator.view.SimulatorWindowController.initialize(SimulatorWindowController.java:35)       ......还有72个

  

我该如何解决?

以下是源代码的下载链接

https://drive.google.com/folderview?id=0B7pxly3GctSNQ1FaajY4LTFOQnM&usp=sharing

0 个答案:

没有答案