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)