Results 1 to 12 of 12
  1. #1
    AnteeN is offline Member
    Join Date
    Dec 2011
    Posts
    11
    Rep Power
    0

    Default Hello All a little List question...

    Hello All...

    File[] files = fd.getSelectedFiles();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < files.length; i++)
    {
    sb.append(files[i].getPath() + "\n");
    list.add(sb.toString());
    }

    This just gets the file and their paths to a list.

    I am trying to extract items from this list with;

    String Path = list.getItem(0);

    But unfortunately i can not convert the string to a filepath...

    which i am going to use in;

    RenderedImage image = (RenderedImage)JAI.create("fileload",ImPath);

    Is there a way?

    i looked at some conversions even with stream one but unfortunately it does not allow as a path...

    regards

    ömer kaya
    METU

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default Re: Hello All a little List question...

    i can not convert the string to a filepath...
    Please explain the problem
    Have you printed out the String to see what it contains?
    Very few Strings are valid filepaths.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,090
    Rep Power
    20

    Default Re: Hello All a little List question...

    What do you mean by "i can not convert the string to a filepath"?
    What happens when you use it as a path?

    The way you are creating your List is incorrect as well.
    Print out the contents of your List after you have filled it and see what I mean.

  4. #4
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: Hello All a little List question...

    Are you sure you know what StringBuilders append method does?

    StringBuilder (Java Platform SE 6)

  5. #5
    AnteeN is offline Member
    Join Date
    Dec 2011
    Posts
    11
    Rep Power
    0

    Default Re: Hello All a little List question...

    Hello again sorry for the late response.

    "C:\Users\Public\Pictures\Sample Pictures\1296.jpg"

    this is the output from;

    String Path = list.getItem(0);

    printed to the console as;

    System.out.println(Path);

    String builder is what i used to divide the selection of files with the multi selection. and write them in the list separated from each other. Hope i am using it correctly.

    Thanks for a lot of responses.

    Waiting.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,090
    Rep Power
    20

    Default Re: Hello All a little List question...

    And what does list.get(1) contain?
    Or list.get(2)?

    Because, from that code up there, they are going to be quite different from what you intend.

  7. #7
    AnteeN is offline Member
    Join Date
    Dec 2011
    Posts
    11
    Rep Power
    0

    Default Re: Hello All a little List question...

    Hello;

    They contain same listings as the getitem(0)

    just raw paths. as windows understands

    nothing more.

    kind regards

    ömer kaya

  8. #8
    AnteeN is offline Member
    Join Date
    Dec 2011
    Posts
    11
    Rep Power
    0

    Default Re: Hello All a little List question...

    sorry for not telling but.

    Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: "C:\Users\Public\Pictures\Sample Pictures\1296.jpg": File not found.

    this is the exception i am getting. the path is valid and the file is there.

    thanks a lot.

    ömer kaya
    METU

  9. #9
    AnteeN is offline Member
    Join Date
    Dec 2011
    Posts
    11
    Rep Power
    0

    Default Re: Hello All a little List question...

    at javax.media.jai.JAI.createNS(JAI.java:1087)
    at javax.media.jai.JAI.create(JAI.java:973)
    at javax.media.jai.JAI.create(JAI.java:1408)

    if it matters these are the external library exceptions.

  10. #10
    AnteeN is offline Member
    Join Date
    Dec 2011
    Posts
    11
    Rep Power
    0

    Default Re: Hello All a little List question...

    Hello All;

    Found my problem.

    I was doing it wrong.

    sb.toString makes the item that i add to the list as a string. So that when i try to get the file out of it it takes as string.

    when i deleted this and use it as just another object it gets it as a path as originally stated.

    so my code was changed like;

    if ( status == JFileChooser.APPROVE_OPTION )
    {
    File[] files = fd.getSelectedFiles(); // Chosen Path's are going to be stored to a array list.
    StringBuilder sb = new StringBuilder(); // String Builder is the class for converting the array into divided strings of choice.
    for (int i = 0; i < files.length; i++) // Reading the files array
    {
    // Dividing path strings in respect of selected files.
    list.add(files[i].getPath()); // Converting to strings <List.Add accepts only Strings>
    }

    }
    else if (status == JFileChooser.CANCEL_OPTION )
    {
    System.out.println("Cancel Selected");
    }
    else
    {
    System.out.println("Selection Error");
    }

    And Image Showing as

    String ImPath = list.getItem(0);
    //ystem.out.println(ImPath);
    RenderedImage image = (RenderedImage)JAI.create("fileload",ImPath);
    int width = image.getWidth();
    int height = image.getHeight();
    System.out.println(width);
    System.out.println(height);
    ScrollingImagePanel panel = new ScrollingImagePanel(image, 512, 512);
    Frame window = new Frame("Scrolling Image Panel Example");
    window.add(panel);
    window.pack();
    window.show();

    Thanks a lot all...

    regards
    ömer kaya
    METU

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,090
    Rep Power
    20

    Default Re: Hello All a little List question...

    Quote Originally Posted by AnteeN View Post
    Hello;

    They contain same listings as the getitem(0)

    just raw paths. as windows understands

    nothing more.

    kind regards

    ömer kaya
    That code int he OP does not do that:
    Java Code:
    import java.util.ArrayList;
    import java.util.List;
    
    public class Scratch {
    
       /**
        * @param args
        */
       public static void main(String[] args) {
          String[] strings = {"First one", "Second one", "Third one"};
          List<String> stringList = new ArrayList<String>();
          StringBuilder sb = new StringBuilder();
          for (String s : strings) {
             sb.append(s);
             stringList.add(sb.toString());
          }
          for (String s : stringList) {
             System.out.println(s);
          }
       }
    }
    The above produces:
    First one
    First oneSecond one
    First oneSecond oneThird one

    So each file path after the first had no hope of being correct.

    Anyway, good to see you corrected your problem.

  12. #12
    AnteeN is offline Member
    Join Date
    Dec 2011
    Posts
    11
    Rep Power
    0

    Default Re: Hello All a little List question...

    Thanks a lot Tolls.

    the problem was the file path <As JAVA Knowns "C:\\...\\[filename]" is stored to the list array but i forced to convert it to a string.
    So that when i asked for the information it returned to me as string not path of file.
    When i deleted the string from it that gave me the right answer.

    This was the problem.

    Thanks a lot for the interest.

    regards
    ömer kaya
    METU

Similar Threads

  1. a linked list question
    By smacker in forum New To Java
    Replies: 5
    Last Post: 05-04-2011, 12:57 PM
  2. Question for a list of objects
    By johnhelen in forum New To Java
    Replies: 4
    Last Post: 02-17-2011, 09:23 PM
  3. List question, I don't understand why...
    By jigglywiggly in forum New To Java
    Replies: 14
    Last Post: 03-21-2010, 08:59 AM
  4. A simple List question
    By right2001 in forum New To Java
    Replies: 2
    Last Post: 02-16-2009, 03:37 AM
  5. Linked List Question
    By CirKuT in forum New To Java
    Replies: 4
    Last Post: 12-10-2008, 06:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •