Results 1 to 4 of 4
- 04-23-2011, 04:17 PM #1
Unexpected text returned from getPath()
I'm simply trying to retrieve the path string from a File object like this:
At this point s = "(java.lang.String)/Applications/Utilities"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();
instead of just "/Applications/Utilities"
Why?
-
I don't seem to have your problem. You don't have another class of your own creation called String, do you?
- 04-23-2011, 04:36 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
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:
kind regards,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); } } } }
JosLast edited by JosAH; 04-23-2011 at 04:37 PM. Reason: too slow again, I'm getting used to it ;-)
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 04-23-2011, 04:51 PM #4
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
-
value returned is zero when it is not
By gedas in forum New To JavaReplies: 21Last Post: 03-27-2011, 07:23 PM -
get url returned by search
By avizana in forum NetworkingReplies: 2Last Post: 03-14-2011, 07:43 PM -
unexpected type
By one in forum New To JavaReplies: 13Last Post: 01-20-2009, 09:32 AM -
Unexpected Error
By Mir in forum New To JavaReplies: 10Last Post: 07-07-2008, 07:57 PM -
An unexpected jumper bug on my IO code?
By cruxblack in forum New To JavaReplies: 7Last Post: 07-29-2007, 08:24 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks