This discussion is archived
2 Replies Latest reply: Jan 3, 2013 7:15 PM by 805536 RSS

imageview

anersantana Newbie
Currently Being Moderated
Im trying to use an absolute path for image, cuz i want to choose an image from another hard drive: I use this on imageview and didnt work:

ima= new ImageView(new Image(getClass().getResource("C:/Users/Alexandra/Documents/Scan.jpg").toString()));

This results on an null string

Edited by: anersantana on 03-ene-2013 14:29
  • 1. Re: imageview
    jsmith Guru
    Currently Being Moderated
    Haven't compiled it, but I'm guessing something like this:
    ima = new ImageView(new Image("file:/C:/Users/Alexandra/Documents/Scan.jpg"));
  • 2. Re: imageview
    805536 Journeyer
    Currently Being Moderated
    For future reference, I think you are misunderstanding what getResource() is for. Class.getResource() is for getting the URL of an item saved to a package inside a jar file. So for instance, if you saved an image named "MyImage.png" inside a package named myprogram.main, the code might look like
    String packageURL = Main.class.getResource("/myprogram/main/MyImage.png").toString();
    Which would give you a url something like jar:file:/some_file_path/MyJarFile.jar!/myprogram/main/MyImage.png

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points