Anchoring elements in Anchor Pane
I just made these three files with Scene Builder:
textfield.fxml:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" fx:controller="mailbox.TextFieldController" xmlns:fx="http://javafx.com/fxml/1">
<TextField fx:id="id" layoutX="252.0" layoutY="39.0" prefHeight="27.0" prefWidth="35.0" />
<TextField fx:id="mitt" layoutX="252.0" layoutY="73.0" />
<TextField fx:id="dest" layoutX="252.0" layoutY="108.0" />
<TextField fx:id="oggetto" layoutX="252.0" layoutY="144.0" />
<TextField fx:id="data" layoutX="308.0" layoutY="39.0" prefHeight="27.0" prefWidth="110.0" />
</AnchorPane>
textarea.fxml:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" fx:controller="mailbox.TextAreaController" xmlns:fx="http://javafx.com/fxml/1">
<TextArea id="textarea" editable="false" layoutX="240.0" layoutY="200.0" prefHeight="200.0" prefWidth="360.0" />
</AnchorPane>
lista.fxml:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" fx:controller="mailbox.ListController" xmlns:fx="http://javafx.com/fxml/1">
<ListView id="listView" layoutY="29.0" prefHeight="371.0" prefWidth="240.0" />
</AnchorPane>
Now, I added the elements both by passing them into the constructor of the Anchor Pane and with the AddAll method, but it didn't work:
public void start(Stage stage) throws Exception {
FXMLLoader listLoader = new FXMLLoader(getClass().getResource("lista.fxml"));
ListController listController = listLoader.getController();
FXMLLoader textareaLoader = new FXMLLoader(getClass().getResource("textarea.fxml"));
TextAreaController textareaController = textareaLoader.getController();
FXMLLoader fieldLoader = new FXMLLoader(getClass().getResource("textfield.fxml"));
TextFieldController fieldController = fieldLoader.getController();
AnchorPane root = new AnchorPane(listLoader.load(), textareaLoader.load(), fieldLoader.load());
//root.getChildren().addAll(listLoader.load(), textareaLoader.load(), fieldLoader.load());
DataModel model = new DataModel();
listController.initModel(model);
textareaController.initModel(model);
Scene scene = new Scene(root, 400, 600);
stage.setScene(scene);
stage.show();
}
This is the error:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
at mailbox.MailBox.start(MailBox.java:38)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Exception running application mailbox.MailBox
java javafx listener anchor
add a comment |
I just made these three files with Scene Builder:
textfield.fxml:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" fx:controller="mailbox.TextFieldController" xmlns:fx="http://javafx.com/fxml/1">
<TextField fx:id="id" layoutX="252.0" layoutY="39.0" prefHeight="27.0" prefWidth="35.0" />
<TextField fx:id="mitt" layoutX="252.0" layoutY="73.0" />
<TextField fx:id="dest" layoutX="252.0" layoutY="108.0" />
<TextField fx:id="oggetto" layoutX="252.0" layoutY="144.0" />
<TextField fx:id="data" layoutX="308.0" layoutY="39.0" prefHeight="27.0" prefWidth="110.0" />
</AnchorPane>
textarea.fxml:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" fx:controller="mailbox.TextAreaController" xmlns:fx="http://javafx.com/fxml/1">
<TextArea id="textarea" editable="false" layoutX="240.0" layoutY="200.0" prefHeight="200.0" prefWidth="360.0" />
</AnchorPane>
lista.fxml:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" fx:controller="mailbox.ListController" xmlns:fx="http://javafx.com/fxml/1">
<ListView id="listView" layoutY="29.0" prefHeight="371.0" prefWidth="240.0" />
</AnchorPane>
Now, I added the elements both by passing them into the constructor of the Anchor Pane and with the AddAll method, but it didn't work:
public void start(Stage stage) throws Exception {
FXMLLoader listLoader = new FXMLLoader(getClass().getResource("lista.fxml"));
ListController listController = listLoader.getController();
FXMLLoader textareaLoader = new FXMLLoader(getClass().getResource("textarea.fxml"));
TextAreaController textareaController = textareaLoader.getController();
FXMLLoader fieldLoader = new FXMLLoader(getClass().getResource("textfield.fxml"));
TextFieldController fieldController = fieldLoader.getController();
AnchorPane root = new AnchorPane(listLoader.load(), textareaLoader.load(), fieldLoader.load());
//root.getChildren().addAll(listLoader.load(), textareaLoader.load(), fieldLoader.load());
DataModel model = new DataModel();
listController.initModel(model);
textareaController.initModel(model);
Scene scene = new Scene(root, 400, 600);
stage.setScene(scene);
stage.show();
}
This is the error:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
at mailbox.MailBox.start(MailBox.java:38)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Exception running application mailbox.MailBox
java javafx listener anchor
Side note from just looking at your code. UsingAnchorPaneas the root does not seem like the best node to use given theFXML'sthat you posted.
– Sedrick
Nov 12 '18 at 15:07
add a comment |
I just made these three files with Scene Builder:
textfield.fxml:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" fx:controller="mailbox.TextFieldController" xmlns:fx="http://javafx.com/fxml/1">
<TextField fx:id="id" layoutX="252.0" layoutY="39.0" prefHeight="27.0" prefWidth="35.0" />
<TextField fx:id="mitt" layoutX="252.0" layoutY="73.0" />
<TextField fx:id="dest" layoutX="252.0" layoutY="108.0" />
<TextField fx:id="oggetto" layoutX="252.0" layoutY="144.0" />
<TextField fx:id="data" layoutX="308.0" layoutY="39.0" prefHeight="27.0" prefWidth="110.0" />
</AnchorPane>
textarea.fxml:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" fx:controller="mailbox.TextAreaController" xmlns:fx="http://javafx.com/fxml/1">
<TextArea id="textarea" editable="false" layoutX="240.0" layoutY="200.0" prefHeight="200.0" prefWidth="360.0" />
</AnchorPane>
lista.fxml:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" fx:controller="mailbox.ListController" xmlns:fx="http://javafx.com/fxml/1">
<ListView id="listView" layoutY="29.0" prefHeight="371.0" prefWidth="240.0" />
</AnchorPane>
Now, I added the elements both by passing them into the constructor of the Anchor Pane and with the AddAll method, but it didn't work:
public void start(Stage stage) throws Exception {
FXMLLoader listLoader = new FXMLLoader(getClass().getResource("lista.fxml"));
ListController listController = listLoader.getController();
FXMLLoader textareaLoader = new FXMLLoader(getClass().getResource("textarea.fxml"));
TextAreaController textareaController = textareaLoader.getController();
FXMLLoader fieldLoader = new FXMLLoader(getClass().getResource("textfield.fxml"));
TextFieldController fieldController = fieldLoader.getController();
AnchorPane root = new AnchorPane(listLoader.load(), textareaLoader.load(), fieldLoader.load());
//root.getChildren().addAll(listLoader.load(), textareaLoader.load(), fieldLoader.load());
DataModel model = new DataModel();
listController.initModel(model);
textareaController.initModel(model);
Scene scene = new Scene(root, 400, 600);
stage.setScene(scene);
stage.show();
}
This is the error:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
at mailbox.MailBox.start(MailBox.java:38)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Exception running application mailbox.MailBox
java javafx listener anchor
I just made these three files with Scene Builder:
textfield.fxml:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" fx:controller="mailbox.TextFieldController" xmlns:fx="http://javafx.com/fxml/1">
<TextField fx:id="id" layoutX="252.0" layoutY="39.0" prefHeight="27.0" prefWidth="35.0" />
<TextField fx:id="mitt" layoutX="252.0" layoutY="73.0" />
<TextField fx:id="dest" layoutX="252.0" layoutY="108.0" />
<TextField fx:id="oggetto" layoutX="252.0" layoutY="144.0" />
<TextField fx:id="data" layoutX="308.0" layoutY="39.0" prefHeight="27.0" prefWidth="110.0" />
</AnchorPane>
textarea.fxml:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" fx:controller="mailbox.TextAreaController" xmlns:fx="http://javafx.com/fxml/1">
<TextArea id="textarea" editable="false" layoutX="240.0" layoutY="200.0" prefHeight="200.0" prefWidth="360.0" />
</AnchorPane>
lista.fxml:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" fx:controller="mailbox.ListController" xmlns:fx="http://javafx.com/fxml/1">
<ListView id="listView" layoutY="29.0" prefHeight="371.0" prefWidth="240.0" />
</AnchorPane>
Now, I added the elements both by passing them into the constructor of the Anchor Pane and with the AddAll method, but it didn't work:
public void start(Stage stage) throws Exception {
FXMLLoader listLoader = new FXMLLoader(getClass().getResource("lista.fxml"));
ListController listController = listLoader.getController();
FXMLLoader textareaLoader = new FXMLLoader(getClass().getResource("textarea.fxml"));
TextAreaController textareaController = textareaLoader.getController();
FXMLLoader fieldLoader = new FXMLLoader(getClass().getResource("textfield.fxml"));
TextFieldController fieldController = fieldLoader.getController();
AnchorPane root = new AnchorPane(listLoader.load(), textareaLoader.load(), fieldLoader.load());
//root.getChildren().addAll(listLoader.load(), textareaLoader.load(), fieldLoader.load());
DataModel model = new DataModel();
listController.initModel(model);
textareaController.initModel(model);
Scene scene = new Scene(root, 400, 600);
stage.setScene(scene);
stage.show();
}
This is the error:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
at mailbox.MailBox.start(MailBox.java:38)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Exception running application mailbox.MailBox
java javafx listener anchor
java javafx listener anchor
edited Nov 12 '18 at 12:41
fabian
50.7k115272
50.7k115272
asked Nov 12 '18 at 12:34
Samoa JoeSamoa Joe
206
206
Side note from just looking at your code. UsingAnchorPaneas the root does not seem like the best node to use given theFXML'sthat you posted.
– Sedrick
Nov 12 '18 at 15:07
add a comment |
Side note from just looking at your code. UsingAnchorPaneas the root does not seem like the best node to use given theFXML'sthat you posted.
– Sedrick
Nov 12 '18 at 15:07
Side note from just looking at your code. Using
AnchorPane as the root does not seem like the best node to use given the FXML's that you posted.– Sedrick
Nov 12 '18 at 15:07
Side note from just looking at your code. Using
AnchorPane as the root does not seem like the best node to use given the FXML's that you posted.– Sedrick
Nov 12 '18 at 15:07
add a comment |
1 Answer
1
active
oldest
votes
Controllers created based on the fx:controller attribute in a fxml are only available after calling load. You need do the getController calls after the AnchorPane creation for this reason:
FXMLLoader listLoader = new FXMLLoader(getClass().getResource("lista.fxml"));
FXMLLoader textareaLoader = new FXMLLoader(getClass().getResource("textarea.fxml"));
FXMLLoader fieldLoader = new FXMLLoader(getClass().getResource("textfield.fxml"));
AnchorPane root = new AnchorPane(listLoader.load(), textareaLoader.load(), fieldLoader.load());
ListController listController = listLoader.getController();
TextAreaController textareaController = textareaLoader.getController();
TextFieldController fieldController = fieldLoader.getController();
DataModel model = new DataModel();
listController.initModel(model);
textareaController.initModel(model);
...
I tried it but I got the same error. Should I post the other classes?
– Samoa Joe
Nov 12 '18 at 12:46
1
You should identify the line that is the cause of the NPE and find out which expression yieldsnull. Going through all the expressions that are dereferenced in your code, after modifying the code there should be no expressions left instartthat could cause a NPE (at mailbox.MailBox.start(MailBox.java:38)shouldn't be the topmost code line mentioned in the NPE stack). Maybe yourinitModelcalls result in NPEs which would be a different question.
– fabian
Nov 12 '18 at 13:16
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262319%2fanchoring-elements-in-anchor-pane%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Controllers created based on the fx:controller attribute in a fxml are only available after calling load. You need do the getController calls after the AnchorPane creation for this reason:
FXMLLoader listLoader = new FXMLLoader(getClass().getResource("lista.fxml"));
FXMLLoader textareaLoader = new FXMLLoader(getClass().getResource("textarea.fxml"));
FXMLLoader fieldLoader = new FXMLLoader(getClass().getResource("textfield.fxml"));
AnchorPane root = new AnchorPane(listLoader.load(), textareaLoader.load(), fieldLoader.load());
ListController listController = listLoader.getController();
TextAreaController textareaController = textareaLoader.getController();
TextFieldController fieldController = fieldLoader.getController();
DataModel model = new DataModel();
listController.initModel(model);
textareaController.initModel(model);
...
I tried it but I got the same error. Should I post the other classes?
– Samoa Joe
Nov 12 '18 at 12:46
1
You should identify the line that is the cause of the NPE and find out which expression yieldsnull. Going through all the expressions that are dereferenced in your code, after modifying the code there should be no expressions left instartthat could cause a NPE (at mailbox.MailBox.start(MailBox.java:38)shouldn't be the topmost code line mentioned in the NPE stack). Maybe yourinitModelcalls result in NPEs which would be a different question.
– fabian
Nov 12 '18 at 13:16
add a comment |
Controllers created based on the fx:controller attribute in a fxml are only available after calling load. You need do the getController calls after the AnchorPane creation for this reason:
FXMLLoader listLoader = new FXMLLoader(getClass().getResource("lista.fxml"));
FXMLLoader textareaLoader = new FXMLLoader(getClass().getResource("textarea.fxml"));
FXMLLoader fieldLoader = new FXMLLoader(getClass().getResource("textfield.fxml"));
AnchorPane root = new AnchorPane(listLoader.load(), textareaLoader.load(), fieldLoader.load());
ListController listController = listLoader.getController();
TextAreaController textareaController = textareaLoader.getController();
TextFieldController fieldController = fieldLoader.getController();
DataModel model = new DataModel();
listController.initModel(model);
textareaController.initModel(model);
...
I tried it but I got the same error. Should I post the other classes?
– Samoa Joe
Nov 12 '18 at 12:46
1
You should identify the line that is the cause of the NPE and find out which expression yieldsnull. Going through all the expressions that are dereferenced in your code, after modifying the code there should be no expressions left instartthat could cause a NPE (at mailbox.MailBox.start(MailBox.java:38)shouldn't be the topmost code line mentioned in the NPE stack). Maybe yourinitModelcalls result in NPEs which would be a different question.
– fabian
Nov 12 '18 at 13:16
add a comment |
Controllers created based on the fx:controller attribute in a fxml are only available after calling load. You need do the getController calls after the AnchorPane creation for this reason:
FXMLLoader listLoader = new FXMLLoader(getClass().getResource("lista.fxml"));
FXMLLoader textareaLoader = new FXMLLoader(getClass().getResource("textarea.fxml"));
FXMLLoader fieldLoader = new FXMLLoader(getClass().getResource("textfield.fxml"));
AnchorPane root = new AnchorPane(listLoader.load(), textareaLoader.load(), fieldLoader.load());
ListController listController = listLoader.getController();
TextAreaController textareaController = textareaLoader.getController();
TextFieldController fieldController = fieldLoader.getController();
DataModel model = new DataModel();
listController.initModel(model);
textareaController.initModel(model);
...
Controllers created based on the fx:controller attribute in a fxml are only available after calling load. You need do the getController calls after the AnchorPane creation for this reason:
FXMLLoader listLoader = new FXMLLoader(getClass().getResource("lista.fxml"));
FXMLLoader textareaLoader = new FXMLLoader(getClass().getResource("textarea.fxml"));
FXMLLoader fieldLoader = new FXMLLoader(getClass().getResource("textfield.fxml"));
AnchorPane root = new AnchorPane(listLoader.load(), textareaLoader.load(), fieldLoader.load());
ListController listController = listLoader.getController();
TextAreaController textareaController = textareaLoader.getController();
TextFieldController fieldController = fieldLoader.getController();
DataModel model = new DataModel();
listController.initModel(model);
textareaController.initModel(model);
...
answered Nov 12 '18 at 12:39
fabianfabian
50.7k115272
50.7k115272
I tried it but I got the same error. Should I post the other classes?
– Samoa Joe
Nov 12 '18 at 12:46
1
You should identify the line that is the cause of the NPE and find out which expression yieldsnull. Going through all the expressions that are dereferenced in your code, after modifying the code there should be no expressions left instartthat could cause a NPE (at mailbox.MailBox.start(MailBox.java:38)shouldn't be the topmost code line mentioned in the NPE stack). Maybe yourinitModelcalls result in NPEs which would be a different question.
– fabian
Nov 12 '18 at 13:16
add a comment |
I tried it but I got the same error. Should I post the other classes?
– Samoa Joe
Nov 12 '18 at 12:46
1
You should identify the line that is the cause of the NPE and find out which expression yieldsnull. Going through all the expressions that are dereferenced in your code, after modifying the code there should be no expressions left instartthat could cause a NPE (at mailbox.MailBox.start(MailBox.java:38)shouldn't be the topmost code line mentioned in the NPE stack). Maybe yourinitModelcalls result in NPEs which would be a different question.
– fabian
Nov 12 '18 at 13:16
I tried it but I got the same error. Should I post the other classes?
– Samoa Joe
Nov 12 '18 at 12:46
I tried it but I got the same error. Should I post the other classes?
– Samoa Joe
Nov 12 '18 at 12:46
1
1
You should identify the line that is the cause of the NPE and find out which expression yields
null. Going through all the expressions that are dereferenced in your code, after modifying the code there should be no expressions left in start that could cause a NPE (at mailbox.MailBox.start(MailBox.java:38) shouldn't be the topmost code line mentioned in the NPE stack). Maybe your initModel calls result in NPEs which would be a different question.– fabian
Nov 12 '18 at 13:16
You should identify the line that is the cause of the NPE and find out which expression yields
null. Going through all the expressions that are dereferenced in your code, after modifying the code there should be no expressions left in start that could cause a NPE (at mailbox.MailBox.start(MailBox.java:38) shouldn't be the topmost code line mentioned in the NPE stack). Maybe your initModel calls result in NPEs which would be a different question.– fabian
Nov 12 '18 at 13:16
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262319%2fanchoring-elements-in-anchor-pane%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Side note from just looking at your code. Using
AnchorPaneas the root does not seem like the best node to use given theFXML'sthat you posted.– Sedrick
Nov 12 '18 at 15:07