Im Anschluss an den Nullpointer ich in initialize Methode der Controller-Klasse bekommen:Erste Nullpointer in Methode initialize-Controller JavaFX
`Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8411)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:352)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:275)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:388)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:387)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
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)
Caused by: 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 sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
... 48 more
Caused by: javafx.fxml.LoadException:
file:/C:/Users/W7/Documents/NetBeansProjects/PivotNSE/dist/run2050028213/PivotNSE.jar!/pivotnse/popupFXML.fxml
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
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 pivotnse.PivotFXController.handleLoadButton(PivotFXController.java:173)
... 58 more
Caused by: java.lang.NullPointerException
at pivotnse.PivotFXController.initialize(PivotFXController.java:294)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
... 66 more`
Was ich versuche zu tun ist, wenn myLoadButton geklickt wird, ein neues Fenster öffnet up und zeigt im Label des neuen Fensters alle Symbole, die gerade "heruntergeladen" werden! (Art wie "Echtzeit-Update" für den Benutzer). Nur damit der Benutzer weiß, was passiert. Es folgt der Code:
public class PivotFXController implements Initializable {
final ObservableList<GetPivots> data = FXCollections.observableArrayList();
@FXML
private TableView<GetPivots> pivotTable;
@FXML
private TableColumn<GetPivots, String> symbolColumn;
@FXML
private TableColumn<GetPivots, String> pivotColumn;
@FXML
private TableColumn<GetPivots, String> r1Column;
@FXML
private TableColumn<GetPivots, String> r2Column;
@FXML
private TableColumn<GetPivots, String> r3Column;
@FXML
private TableColumn<GetPivots, String> s1Column;
@FXML
private TableColumn<GetPivots, String> s2Column;
@FXML
private TableColumn<GetPivots, String> s3Column;
@FXML
private Label statusLabel;
@FXML
private Button myLoadButton;
@FXML
private Button doneButton;
@FXML
private TextField symbolField;
private String SYMBOLS_FILE = "SYMBOLS.txt";
private static List<String> symbolList = new ArrayList<String>();
private boolean handleSymbol(String symbol) {
System.out.println(symbol + " is the input");
// statusLabel.setText("Downloading... " + symbol);
FetchDataNSE fdn = new FetchDataNSE();
if (fdn.getDataNSE(symbol).size() > 0) {
CalculatePivot cp = new CalculatePivot(fdn.getDataNSE(symbol));
GetPivots gp = new GetPivots(cp);
data.add(gp);
// statusLabel.setText(symbol + " " + "Downloaded!");
return true;
}
return false;
}
@FXML
private void handleLoadButton(ActionEvent event) throws IOException {
Stage stage;
Parent root;
if (event.getSource() == myLoadButton) {
//get reference to the button's stage
stage = (Stage) myLoadButton.getScene().getWindow();
//load up OTHER FXML document
root = FXMLLoader.load(getClass().getResource("popupFXML.fxml"));// <-- ****this line is causing problem**** I am getting NULLPOINTEREXCEPTION from 1st line in `initialize` method WHY?
stage.setScene(new Scene(root));
stage.setTitle("DOWNLOADING STATUS");
stage.initModality(Modality.APPLICATION_MODAL);
stage.showAndWait();
loadSymbols();
} else {
stage = (Stage) doneButton.getScene().getWindow();
root = FXMLLoader.load(getClass().getResource("pivotFXGUI.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}
private void loadSymbols() {
data.clear();
symbolList.clear();
BufferedReader br = null;
try {
String sCurrentLine;
br = new BufferedReader(new FileReader(SYMBOLS_FILE));
while ((sCurrentLine = br.readLine()) != null) {
symbolList.add(sCurrentLine.trim());
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null) {
br.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
for (String sym : symbolList) {
statusLabel.setText("Downloading... " + sym);
handleSymbol(sym);
}
statusLabel.setText("LOADING SYMBOLS DONE!");
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// 1st line below gives NullPointerException! why does that happen?
symbolColumn.setCellValueFactory(new PropertyValueFactory<>("symbolProperty"));
pivotColumn.setCellValueFactory(new PropertyValueFactory<>("pivotProperty"));
r1Column.setCellValueFactory(new PropertyValueFactory<>("r1Property"));
r2Column.setCellValueFactory(new PropertyValueFactory<>("r2Property"));
r3Column.setCellValueFactory(new PropertyValueFactory<>("r3Property"));
s1Column.setCellValueFactory(new PropertyValueFactory<>("s1Property"));
s2Column.setCellValueFactory(new PropertyValueFactory<>("s2Property"));
s3Column.setCellValueFactory(new PropertyValueFactory<>("s3Property"));
pivotTable.setItems(data);
// myLoadButton.fire();
// pivotTable.getColumns().addAll(symbolColumn,s3Column, s2Column,s1Column, pivotColumn, r1Column, r2Column, r3Column );
}
}
`
Warum in der „initialisieren“ Methode werfen Nullpointer die erste Linie ist !? Was mache ich falsch in handleLoadButton(..)
Methode und initialize(..)
Methode? Wenn ich alles von initialize
Methode Programm entfernen neues Fenster öffnet sich, wenn ich myLoadButton klicken, dann aber Nullpointer tritt auf, wenn loadSymbols()
Methode aufgerufen wird ...
AUCH ::: at pivotnse.PivotFXController.handleLoadButton(PivotFXController.java:173) ... 58 more Caused by: java.lang.NullPointerException at pivotnse.PivotFXController.initialize(PivotFXController.java:294)
Linie 173 folgt ::: root = FXMLLoader.load(getClass().getResource("popupFXML.fxml"));
und Zeile 294 ist die erste Zeile in initialize()
Methode.
Bitte kochen Sie Ihren Code auf das Minimum herunter, die das Problem zeigt. Nobobody will solch eine große Kopie/Paste Wüste lesen. – Heri
können Sie irgendwo die Dateien hosten? – GOXR3PLUS
Ich frage mich, warum das Laden von 'popupFXML.fxml' '' PivotFXController.initialize() 'an erster Stelle auslösen würde? Sie würden erwarten, dass es 'PopupFXML.initialize()' aufruft, nein? Habe ein 'fx: controller =" "Attribut in' popupFXML.fxml' und was sagt es? –
Arjan