NPE in FileChooser

I am trying to run some kind of javafx application under windows 7. It works fine under archlinux.

I open the file selection dialog as follows:

@Override public void start(final Stage primaryStage) { FileChooser fileChooser = new FileChooser(); fileChooser.setInitialDirectory(myInitialDir); FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("Wav files (*.wav)", "*.wav"); fileChooser.getExtensionFilters().add(extFilter); File file = fileChooser.showOpenDialog(primaryStage); } 

As I mentioned above - everything is fine under linux, but under windows I get weird NPE:

 Error:80070057 in SHCreateItemFromParsingName((PCWSTR)folder, NULL, IID_IShellItem, (void **)&pItem) COM Error:80070057 0@0. Error:80004005 in pOpenDialog->GetResults(&pFiles) COM Error:80004005 5>?>7=0==0O >H81:0 java.lang.NullPointerException at com.sun.glass.ui.CommonDialogs.showFileChooser(CommonDialogs.java:120) at com.sun.javafx.tk.quantum.QuantumToolkit.showFileChooser(QuantumToolkit.java:1486) at javafx.stage.FileChooser.showDialog(FileChooser.java:285) at javafx.stage.FileChooser.showOpenDialog(FileChooser.java:234) at ru.gkalabin.diploma.gui.equalizer.EqualizerDemo$1.handle(EqualizerDemo.java:107) 

Any ideas how I can fix this?

+4
source share
1 answer

This is problem:

RT-21999 Win: FileChooser does not accept a valid start directory

The problem affects version: 2.2; Fix Version / s: Lombard, so the fix is ​​available in JFX8 (in JDK8).

To fix the problem, call <fileName>.getCanonicalPath() on the start folder.


Comments from the developer:

This issue applies to Windows 7. It does not play on older versions of Windows.

The workaround is to pass the absolute path as the source directory for selecting the file (see File.getAbsolutePath () / getCanonicalPath ()).

And user comment:

Jason Winnebeck added a comment - March, 18 2013 04:30 I came across this, as well as the same COM errors that were printed on stderr, and threw a NullPointerException. At first I tried getAbsolutePath, but this does not work for all paths, for some you should use getCanonicalPath, fortunately I found this ticket that gave me this workaround. So, I have no additional additional information, except here is the groovy code that reproduces it:

 public void openFile() throws IOException { FileChooser chooser = new FileChooser() chooser.title = "Select FXML" chooser.setInitialDirectory( new File( "." ) ); chooser.extensionFilters.add( new FileChooser.ExtensionFilter( "FXML or SVG Files", ["*.fxml", "*.svg"] )) Window window = sceneProperty.get().window File selected = chooser.showOpenDialog( window ) } 

The error occurs regardless of other settings (extension filter that is used by Window or null). Using new File( "." ).canonicalFile fixes the problem, so based on another report, it seems to be there . and .. in transit is a likely cause.

+4
source

Source: https://habr.com/ru/post/1483438/


All Articles