Tags: array, case, creating, directory, exception, file, files, gifs, java, listing, malformed, points, programming, protocol, url
Need help with "Malformed URL: No Protocol" exception
I'm creating a File that points to a directory. Using File.list() I'm getting an array listing all the files (in this case, .gifs) in the directory. I'm trying to create a URL pointing to each one of these .gifs, but I get a "Malformed URL Exception: No protocol" for each one. My guess is that the Java URL class doesn't know what to do with the gif. Does anyone know any way around this?
String iconRootDir = "./Icons";
File iconRoot = new File(iconRootDir);
String fileList = iconRoot.list();
QLChoiceButton tempButton = null;
for (int i = 0; i < fileList.length; i++)
tempButton = new QLChoiceButton(this, new URL(iconRootDir+"/"+fileList[i])); //exception thrown here
} //end for
} //end try
"There's nothing more dangerous than a resourceful idiot." --Dilbert
Leave a comment...
- 2 Comments
- Bit of a guess, but try having a protocl of "file://" on the front.
You'll also need a "/" on the front of the file path. so you'll get:
file:///C:/blah/blah.doc in windows.
Brainbench MVP for Java
http://www.brainbench.com#1; Sat, 10 Nov 2007 02:45:00 GMT
- That did it (I feel dumb! :) ). Thanks!
"There's nothing more dangerous than a resourceful idiot." --Dilbert#2; Sat, 10 Nov 2007 02:46:00 GMT