1

I'm using Dropbox API V2 to download images from my Dropbox to my Java Program. I save them in "/src/main/Resources/Downloads/" and then want to get the image.jpg at the same time the program is running after downloaded.

1) The first time the program downloads the image and run this I get "Invalid URL or resource not found" error:

Button button1 = new Button();
Image thumbnail = new Image("/Downloads/image.jpg");
button1.setGraphic(new ImageView(thumbnail));

2) Second time when I have closed the program and the file is already saved in Resources it works.

What am I missing?

4
  • The image probably wasn't saved at the time of / before the call in #1. Commented Dec 4, 2016 at 19:33
  • are you sure the download function returns AFTER the image has downloaded successfully? Put in a sleep of sufficient time to test this Commented Dec 4, 2016 at 19:38
  • I just made a Thread.sleep(70000) just to be super sure. But still didn't do the trick. It seems like the images downloaded isn't saved in resource folder until I close the program. Commented Dec 4, 2016 at 19:46
  • Please use a code block {} instead of quotes to highlight your code - it will look better Commented Dec 4, 2016 at 19:50

1 Answer 1

2

Found a solution:

String path = "/src/main/Resources/";

File file = new File(path + i.getLocalPathThumbnail());
String localUrl = file.toURI().toURL().toString();
Image thumbnail = new Image(localUrl, false);
Sign up to request clarification or add additional context in comments.

1 Comment

A better method is to use file.toURI().toURL().toExternalForm()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.