Tags: array, case, creating, directory, exception, file, files, gifs, java, listing, malformed, points, programming, protocol, url
Need help with "Malformed URL: No Protocol" exception
On Java Studio » Java Programming
1,377 words with 2 Comments; publish: Tue, 05 Feb 2008 21:20:00 GMT; (15078.13, « »)
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?
try
{
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
buttonScrollPane.add(tempButton);
} //end for
} //end try
"There's nothing more dangerous than a resourceful idiot." --Dilbert
http://java-program.developerfaqs.com/q_java-programming_204219.html
All Comments
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.
Bayard
bayard.java-program.developerfaqs.com.generationjava.com
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