0

I am getting a runtime exception for this simple program i wrote. Exception occurs while "event" method is envoked(I think)

example.java

public class Example extends Application {

    @Override
    public void start(Stage primaryStage) {

        try {
        Parent roo11 = FXMLLoader.load(getClass().getResource("example.fxml"));

         Scene scene = new Scene(roo11);

        primaryStage.setTitle("D-A-S-H Messenger");
        primaryStage.setScene(scene);
        primaryStage.show();

        } catch (IOException ex) {
            Logger.getLogger(Example.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

}

example.fxml

fxml code

ExampleController.java

public class ExampleController {


       @FXML JFXTextArea area;

       @FXML JFXTextField field;

       @FXML ImageView img;

     @FXML public void event(MouseEvent e){ 

      field.setOnMouseClicked((MouseEvent event) ->
            {
            area.setText("Hello\n");

            });   
     }
 }       

Whenever I click the textfield exception occurs:

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException

fabian
  • 80,457
  • 12
  • 86
  • 114
Aashir
  • 1
  • 1
  • Did you add the Controller Class to your `FXML` file? – Yahya Jun 03 '17 at 23:54
  • 1
    Welcome to SO. Add the controller to the fxml file. In future questions try to format your code, and add all what needed as code rather than as links. – c0der Jun 04 '17 at 04:05
  • it has been added. program works and when you click it program gives the exception meaning the working is fine its just after that is suppose to happend doesnt happen. – Aashir Jun 04 '17 at 16:19
  • my problem is i can not access the TextField or TextArea by using their id – Aashir Jun 04 '17 at 16:21

0 Answers0