Issue
I am trying to retrieve an Image from the web and then put in to a Image view in Java FX. How ever I am getting a mismatch error of Unresolved compilation problem: Type mismatch: cannot convert from Buffered Image to Image. How can I retrieve the Image on from the web then display it on to my Application.
My Code
URL url2 = new URL("http://mars.jpl.nasa.gov/msl-raw-images/proj/msl/redops/ods/surface/sol/01004/opgs/edr/fcam/FLB_486615455EDR_F0481570FHAZ00323M_.JPG");
Image image = ImageIO.read(url2);
imageV.setImage(image);
Solution
Don’t try to convert the image using swing and imageio. Also don’t create a URL object. None of that is necessary.
Just load the image directly from the url string using the image constructor.
As noted in comments, you need to directly access the image on the server, not via a redirected location:
if I change the protocol from http to https then it works. My guess is the website automatically upgrades to HTTPS, which I think results in a redirect, and I would not be surprised if JavaFX's image-loading implementation doesn't handle that.
Answered By - jewelsea
Answer Checked By - Mildred Charles (JavaFixing Admin)