1

My program is structured package and control on the interface as follows

**+ Browser          : BrowserController.class** 
                     -@FXML
                      private SplitPane spHTMLParser;
                      @FXML
                      private TextField txtURL;
                      @FXML
                      private Button btnSearch;
                      @FXML
                      private WebView browser;

**+ Browser/Console  : ConsoleController.class**
                      @FXML
                      private Label lblURL;  

In the browser page when the user clicks the btnSearch,I will show webview site with user input url. When the process is complete I want to show the Console.fxml in Browser.fxml with SplitPane and When the console is displayed, I'd label can get value url . Please help me!

 @FXML
    void btnSearch(ActionEvent event) {
        String url = txtURL.getText().trim();
        if (!url.isEmpty()) {
            WebEngine  webEngine = browser.getEngine();
            progressBar.progressProperty().bind(webEngine.getLoadWorker().progressProperty());
            webEngine.load(url);
            webEngine.getLoadWorker().stateProperty().addListener((ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newValue) -> {
                switch (newValue) {
                    case SUCCEEDED:
                        if (count++ != 0) {
                            btnNext.setDisable(false);
                        }
                        btnBack.setDisable(false);
                        progressBar.setVisible(false);
                        {
                            try {
                                FXMLLoader fxmlLoader = new FXMLLoader();
                                Pane pnConsole = fxmlLoader.load(getClass().getResource("console/Console.fxml").openStream());
                                spHTMLParser.getItems().add(pnConsole);
                                spHTMLParser.setDividerPositions(0.5);
                            } catch (IOException ex) {
                                Logger.getLogger(BrowserController.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                        break;
                }
            });
        }
    }

Load events url successful work exactly but I got an error when trying to call the other pane via fxml

Its error messages with commands

Pane pnConsole = fxmlLoader.load(getClass().getResource("console/Console.fxml").openStream());




Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
        at publishers.controllers.resources.browser.BrowserController.lambda$webView$4(BrowserController.java:144)
        at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:182)
        at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
        at javafx.beans.property.ReadOnlyObjectPropertyBase.fireValueChangedEvent(ReadOnlyObjectPropertyBase.java:74)
        at javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:102)
        at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
        at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146)
        at javafx.scene.web.WebEngine$LoadWorker.updateState(WebEngine.java:1260)
        at javafx.scene.web.WebEngine$LoadWorker.dispatchLoadEvent(WebEngine.java:1371)
        at javafx.scene.web.WebEngine$LoadWorker.access$1200(WebEngine.java:1253)
        at javafx.scene.web.WebEngine$PageLoadListener.dispatchLoadEvent(WebEngine.java:1240)
        at com.sun.webkit.WebPage.fireLoadEvent(WebPage.java:2400)
        at com.sun.webkit.WebPage.fwkFireLoadEvent(WebPage.java:2244)
        at com.sun.webkit.network.URLLoader.twkDidFinishLoading(Native Method)
        at com.sun.webkit.network.URLLoader.notifyDidFinishLoading(URLLoader.java:838)
        at com.sun.webkit.network.URLLoader.lambda$didFinishLoading$96(URLLoader.java:829)
        at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(WinApplication.java:191)
        at java.lang.Thread.run(Thread.java:745)
Touya Akira
  • 301
  • 4
  • 14
  • That just looks like the path to the FXML file is wrong. E.g. in the top code block you seem to suggest you have a package called `Console` but in the code where you try to load the FXML you reference a package called `console`. Not sure if that is just a typo or if something else is wrong. – James_D Oct 18 '16 at 01:50
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – fabian Oct 18 '16 at 08:19
  • Hm why not simply using `fxmlLoader.load(getClass().getResource("console/Console.fxml)");`?I am curious... – GOXR3PLUS Oct 18 '16 at 09:31
  • 1
    Hi Thank you for helping,I was wrong path error. @GoXR3Plus I find such xml calling on here, http://stackoverflow.com/questions/10751271/accessing-fxml-controller-class I do not know where it's different – Touya Akira Oct 18 '16 at 10:20

0 Answers0