Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

    Default Unexpected text returned from getPath()

    I'm simply trying to retrieve the path string from a File object like this:

    Java Code:
    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(new File("."));
    fc.setDialogTitle("File Chooser");
    if (fc.showOpenDialog(mainPanel) == 0) {
        if ((inFile = fc.getSelectedFile()) != null)
        {
            String s = inFile.getPath();
    At this point s = "(java.lang.String)/Applications/Utilities"
    instead of just "/Applications/Utilities"
    Why?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,010
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by madroadbiker View Post
    At this point s = "(java.lang.String)/Applications/Utilities"
    instead of just "/Applications/Utilities"
    Why?
    It works for me (after adding a bit of code to make your example runnable). I have no idea where that "(java.lang.String)" prefix comes from ...

    This is the code I ran:

    Java Code:
    import java.io.File;
    
    import javax.swing.JFileChooser;
    
    public class T {
    	public static void main(String[] args) {
    		File inFile;
    		JFileChooser fc = new JFileChooser();
    		fc.setCurrentDirectory(new File("."));
    		fc.setDialogTitle("File Chooser");
    
    		if (fc.showOpenDialog(null) == 0) {
    		    if ((inFile = fc.getSelectedFile()) != null)
    		    {
    		        String s = inFile.getPath();	
    		        System.out.println(s);
    		    }
    		}
    	}
    }
    kind regards,

    Jos
    Last edited by JosAH; 04-23-2011 at 04:37 PM. Reason: too slow again, I'm getting used to it ;-)
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

    Default

    When I ran your code in a new project, it worked fine. So I did a clean and build and the problem went away. I don't understand what happened. I must have done something somewhere in my code that got cleaned up after a clean and build. I guess I better do a clean build more often or at least whenever I encounter strange problems like this.
    Thanks for your help.

Similar Threads

  1. value returned is zero when it is not
    By gedas in forum New To Java
    Replies: 21
    Last Post: 03-27-2011, 07:23 PM
  2. get url returned by search
    By avizana in forum Networking
    Replies: 2
    Last Post: 03-14-2011, 07:43 PM
  3. unexpected type
    By one in forum New To Java
    Replies: 13
    Last Post: 01-20-2009, 09:32 AM
  4. Unexpected Error
    By Mir in forum New To Java
    Replies: 10
    Last Post: 07-07-2008, 07:57 PM
  5. An unexpected jumper bug on my IO code?
    By cruxblack in forum New To Java
    Replies: 7
    Last Post: 07-29-2007, 08:24 AM

Posting Permissions

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