title: java.lang.NoClassDefFoundError: javafx/embed/swing/SwingFXUtils
body: <p>I am getting this error every time I attempt to save an image. I can select the image through this code and I press the save button but then I do not find the saved image on my pc in any place instead I obtain the following error. I am using eclipse 2020-9 and java version 15.0.1.
  This is the error:
  java.lang.NoClassDefFoundError: javafx/embed/swing/SwingFXUtils
  Any help please?</p>
  <pre><code>package application;
  
  
  import java.awt.Desktop;
  import java.io.File;
  import java.io.IOException;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import javafx.application.Application;
  import javafx.embed.swing.SwingFXUtils;
  import javafx.event.ActionEvent;
  import javafx.event.EventHandler;
  import javafx.geometry.Insets;
  import javafx.geometry.Pos;
  import javafx.scene.Scene;
  import javafx.scene.control.Button;
  import javafx.scene.control.Label;
  import javafx.scene.control.Menu;
  import javafx.scene.control.MenuBar;
  import javafx.scene.control.MenuItem;
  import javafx.scene.image.Image;
  import javafx.scene.image.ImageView;
  import javafx.scene.layout.StackPane;
  import javafx.scene.layout.VBox;
  import javafx.stage.FileChooser;
  import javafx.stage.Stage;
  import javax.imageio.ImageIO;
  
  /**
   *
   * @web http://java-buddy.blogspot.com
   */
  public class Main extends Application {
  
      @Override
      public void start(Stage primaryStage) {
          
          final FileChooser fileChooser = new FileChooser();
          final Button openButton = new Button(&quot;Open Image&quot;);
  
          openButton.setOnAction(
              new EventHandler&lt;ActionEvent&gt;() {
                  @Override
                  public void handle(final ActionEvent e) {
                      setExtFilters(fileChooser);
                      File file = fileChooser.showOpenDialog(primaryStage);
                      if (file != null) {
                          openNewImageWindow(file);
                      }
                  }
              });
  
          
          StackPane root = new StackPane();
          root.getChildren().add(openButton);
          
          Scene scene = new Scene(root, 400, 150);
          
          primaryStage.setTitle(&quot;java-buddy.blogspot.com&quot;);
          primaryStage.setScene(scene);
          primaryStage.show();
      }
  
      public static void main(String[] args) {
          launch(args);
      }
      
      private void setExtFilters(FileChooser chooser){
          chooser.getExtensionFilters().addAll(
                  new FileChooser.ExtensionFilter(&quot;All Images&quot;, &quot;*.*&quot;),
                  new FileChooser.ExtensionFilter(&quot;PNG&quot;, &quot;*.png&quot;)
          );
      }
              
      private void openNewImageWindow(File file){
          Stage secondStage = new Stage();
          
          MenuBar menuBar = new MenuBar();
          Menu menuFile = new Menu(&quot;File&quot;);
          MenuItem menuItem_Save = new MenuItem(&quot;Save Image&quot;);
          menuFile.getItems().addAll(menuItem_Save);
          menuBar.getMenus().addAll(menuFile);
          
          Label name = new Label(file.getAbsolutePath());
          Image image = new Image(file.toURI().toString());
          ImageView imageView = new ImageView();
          
          menuItem_Save.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
  
              @Override
              public void handle(ActionEvent event) {
                  FileChooser fileChooser = new FileChooser();
                  fileChooser.setTitle(&quot;Save Image&quot;);
                  
                  File file = fileChooser.showSaveDialog(secondStage);
                  if (file != null) {
                      try {
                          ImageIO.write(SwingFXUtils.fromFXImage(imageView.getImage(),
                                  null), &quot;png&quot;, file);
                      } catch (IOException ex) {
                          Logger.getLogger(
                              Main.class.getName()).log(Level.SEVERE, null, ex);
                      }
                  }
              }
          });
  
          final VBox vbox = new VBox();
          vbox.setAlignment(Pos.CENTER);
          vbox.setSpacing(10);
          vbox.setPadding(new Insets(0, 10, 0, 10));
          vbox.getChildren().addAll(name, imageView);
          
          imageView.setFitHeight(400);
          imageView.setPreserveRatio(true);
          imageView.setImage(image);
          imageView.setSmooth(true);
          imageView.setCache(true);
          
          Scene scene = new Scene(new VBox(), 400, 350);
          ((VBox)scene.getRoot()).getChildren().addAll(menuBar, vbox);
          
          secondStage.setTitle(file.getName());
          secondStage.setScene(scene);
          secondStage.show();
      }
      
  }
  </code></pre>