通常,我一直在JavaFX中使用FileChooser。超级容易做到这一点。只需调用它,它将打开一个新窗口,您可以在其中选择文件。做完了!

但是FileChooser在Android和Iphone上不起作用。我必须选择StorageService

https://docs.gluonhq.com/charm/javadoc/5.0.1/com/gluonhq/charm/down/plugins/StorageService.html

File privateStorage = Services.get(StorageService.class)
                          .flatMap(StorageService::getPrivateStorage)
                          .orElseThrow(() -> {
                              new FileNotFoundException("Could not access private storage.");
                          });


但是这里的问题是它给出了一个错误:

The method orElseThrow(Supplier<? extends X>) in the type Optional<File> is not applicable for the arguments (() -> {})


那么我该如何解决呢?

最佳答案

您可以这样做:

Optional.empty().orElseThrow(FileNotFoundException::new);


要么

Optional.empty().orElseThrow(()->new FileNotFoundException("Some exception"));


要么

Optional.empty().orElseThrow(() -> {
            return new FileNotFoundException("Some exception");
        });


值得一读:When are braces optional in Java 8 lambda syntax?

关于java - StorageService在GluonHQ框架上给出错误-我该如何解决?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57441232/

10-10 22:20