I have a java class file vovlo.java, it is lower

vovlo.java

package My_classes; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import javafx.fxml.FXML; import javafx.scene.control.TextArea; /** * * @author Администрация */ public class vovlo { @FXML TextArea textArea; private String ff; public void setTextfromFolder(String ff){ this.ff = ff; File fileFOL = new File(ff); try { Scanner s = new Scanner(fileFOL).useDelimiter("\n+"); while (s.hasNext()) { if (s.hasNextInt()) { // check if next token is an int textArea.appendText(s.nextInt() + "\n "); // display the found integer } else { 

ERROR NULL ---

  textArea.appendText(s.next() + " "+"\n"); // ERROR } } } catch (FileNotFoundException ex) { System.err.println(ex); } }; }` 

I want the List file to run this class when executing if, and I could only change the path to the file as String ff to shrink the number of lines. If I just put the text from the class in if everything works.

List

  @FXML public void GetDataFromTXT(ActionEvent event) throws FileNotFoundException { LocalDateTime currentTime = LocalDateTime.now(); int year = currentTime.getYear(); String dada = "DADA"; String DAY = (String)Textday.getText(); if(DAY.equals("1") & MonChoose.getValue().toString().equals("January")){ vovlo koko = new vovlo(); 

(ERROR NULL) 36-- below

 koko.setTextfromFolder("./src/yourDATA/2017/JANUARY/1 JANUARY.txt");//ERROR }; }} 

Mistake

 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:8413) 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:380) at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:294) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:416) at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389) at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:415) 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: java.lang.NullPointerException at My_classes.vovlo.setTextfromFolder(vovlo.java:36) at My_classes.List.GetDataFromTXT(List.java:94) ... 58 more 

This is all related to the FXML file.

 <?xml version="1.0" encoding="UTF-8"?> <?import javafx.geometry.*?> <?import javafx.scene.paint.*?> <?import javafx.scene.effect.*?> <?import javafx.scene.canvas.*?> <?import javafx.scene.media.*?> <?import javafx.scene.text.*?> <?import java.lang.*?> <?import java.util.*?> <?import javafx.scene.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <AnchorPane id="AnchorPane" prefHeight="298.0" prefWidth="406.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="My_classes.List"> <children> <TextField fx:id="Textday" layoutX="10.0" layoutY="41.0" onAction="#GetDataFromTXT" prefHeight="24.0" prefWidth="30.0" /> <ChoiceBox fx:id="MonChoose" layoutX="40.0" layoutY="41.0" prefHeight="24.0" prefWidth="109.0" /> <TextArea fx:id="textArea" layoutX="149.0" prefHeight="300.0" prefWidth="257.0" /> <Button fx:id="close3" layoutX="-1.0" mnemonicParsing="false" onAction="#close3" prefHeight="25.0" prefWidth="30.0" text="Button" /> <Label layoutX="10.0" layoutY="25.0" prefHeight="16.0" prefWidth="150.0" text="Enter the day below" /> <Button fx:id="But" layoutX="46.0" layoutY="109.0" mnemonicParsing="false" onAction="#GetDataFromTXT" text="Button" /> </children> <padding> <Insets bottom="2.0" left="2.0" right="2.0" top="2.0" /> </padding> <rotationAxis> <Point3D /> </rotationAxis> <opaqueInsets> <Insets bottom="10.0" left="13.0" right="12.0" top="11.0" /> </opaqueInsets> </AnchorPane> 
  • I enter the number 1 in Textday (TextField) and select month in MonChoose (ChoiceBox) January I press the But (Button) button and the text from file 1 JANUARY should appear in the textArea - Kolia
  • Probably here you can not figure out without 100 grams. - Kolia
  • I will only give a couple of tips: 1) if you want your code to be read by someone, follow the conventions - write the names of the methods and variables with a small letter, the names of the classes - with a large one, etc., your code is difficult to read. 2) Try to localize your problem yourself and reproduce it in a small piece of code, and place this fragment here. Then there will be much more chances that someone will read and answer. Few people have the time and desire to read the code sheets without emergency. See en.stackoverflow.com/help/mcve - m. vokhm
  • 36 line of volvo class, object is null , what is this line? - Bohdan Korinnyi
  • four
    vovlo.textArea is null there, nobody has put it, because an instance of the vovlo class is created via new, not via FXMLLoader (judging by the @FXML annotation) - Ruslan P.

1 answer 1

You do not have the correct controller in the fxml file, namely fx:controller="My_classes.List" . Change to My_classes.volvo , the My_classes.volvo annotation works in the controller. Introduction to FXML

  • Thank you for your help. - Kolia