Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8350169

JavaFX FileChooser returns null when selecting file from Android device

XMLWordPrintable

    • x86_64
    • windows

      ADDITIONAL SYSTEM INFORMATION :
      Windows 7 / 10 64bit, Java OpenJDK 19.0.1+10-21, JavaFX 21.0.4

      A DESCRIPTION OF THE PROBLEM :
      When I call fileChooser.showOpenDialog the file chooser is displayed correctly. When I browse the attached Android phone storage (did not test with iPhone, lack of iPhone) I can see all the files. When I select a file, the dialog returns to the java code, but the result is NULL (the selected file is NULL). No exception is thrown.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Attach an Android phone to your windows system. Create and show a javafx file chooser dialog, browse a file from the attached phone's storage and open it.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      a valid File object is returned
      ACTUAL -
      NULL is returned

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.FileChooser;
      import javafx.stage.Stage;

      import java.io.File;

      public class FileChooserTest
      {
          private static class FXTest extends Application
          {

              @Override
              public void start(Stage primaryStage) throws Exception
              {
                  Button button = new Button("Choose file");
                  button.setOnAction(event ->
                  {
                      FileChooser fc = new FileChooser();
                      File selectedFile = fc.showOpenDialog(primaryStage);

                      assert selectedFile != null;
                  });

                  BorderPane bp = new BorderPane();
                  bp.setCenter(button);

                  Scene sc = new Scene(bp, 320, 200);

                  primaryStage.setScene(sc);
                  primaryStage.show();
              }
          }

          public static void main(String[] args)
          {
              Platform.startup(() ->
              {
                  try
                  {
                      new FXTest().start(new Stage());
                  }
                  catch (Exception e)
                  {
                      throw new RuntimeException(e);
                  }
              });
          }
      }

      ---------- END SOURCE ----------

            jvos Johan Vos
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: