0

I am new to javafx. Recently i try to do a program which can change an image in imageview by click a button to switch. Errors occur

@FXML
private ImageView imgView;
@FXML
private Button btnChange;

@FXML
void changeImage (ActionEvent event) throws IOException
{
    Image image = new Image(getClass().getResource("Yuumi.jpg").toString());
    imgView.setImage(image);

}

This is my project and the FXML code


This is my FXML.fxml code https://drive.google.com/open?id=1vQiMXxrRWd84YWcqmQO3xQx0Q1DdIBYt


The errors https://drive.google.com/open?id=1UwVzeEAp1YlhwP0xHZfxnioxEk2BAoC4


My FXML controller https://drive.google.com/file/d/1-7bAKoLhbLcC5bR4_boCG_O57sXPZpX_/view

Helo World
  • 51
  • 7
  • Your screen capture does not display the entire stack trace. Somewhere in the actual stack trace there should be a reference to the code you wrote. So post the full stack trace. And **please** try using "copy/paste" rather than posting a screen capture. You should also post your code so that we can correlate it with the stack trace. And also use "copy/paste" to post your code. No screen capture. – Abra May 09 '19 at 05:19
  • The entire trace https://drive.google.com/open?id=1UwVzeEAp1YlhwP0xHZfxnioxEk2BAoC4 – Helo World May 09 '19 at 07:21
  • We require the necessary info to be posted in the question itself. A link to code/error messages is insufficient. – fabian May 09 '19 at 10:21

1 Answers1

1

From the stack trace you provided, the problem is clearly stated, namely

Caused by: java.lang.IllegalArgumentException: Can not set java.awt.Button field application.MainController.btnChange to javafx.scene.control.Button

Looks like you imported java.awt.Button instead of javafx.scene.control.Button in your code - that I also asked you to provide and which you didn't, so I can't verify that this really is your problem.

EDIT

Selected lines from your MainController class...

import java.awt.Button;

@FXML
private Button btnChange;

Can you see the problem?

Abra
  • 19,142
  • 7
  • 29
  • 41
  • My main java https://drive.google.com/open?id=1oCiBMqL0q3gNjckfbhwaaCRGhUJeMcXQ my FXML.fxml code https://drive.google.com/open?id=1vQiMXxrRWd84YWcqmQO3xQx0Q1DdIBYt – Helo World May 09 '19 at 08:08
  • My FXML controller https://drive.google.com/open?id=1-7bAKoLhbLcC5bR4_boCG_O57sXPZpX_ – Helo World May 09 '19 at 08:12
  • I think you can search through your code for `java.awt.Button`, can't you? You probably just need to replace it with `javafx.scene.control.Button`. Or do you just want me to do all the work for you? – Abra May 09 '19 at 08:18
  • Its working. Thank you so much – Helo World May 09 '19 at 12:17