tags:

views:

15900

answers:

3

I am currently calling the following line of code:

java.net.URL connection_url = new java.net.URL("http://:/path");

and when it executes I get the above exception. Any ideas as to why this is happening?

A: 

As a side note, you should be using URI because Java URL class is screwed up. (The equals method I believe)

jjnguy
Not sure why the parent got modded down, but it might be a good idea to use URI in place of URL depending on what you're doing. See: http://www.symphonious.net/2007/03/29/javaneturl-or-javaneturi/
Sam Merrell
+1  A: 

That url string looks like it's invalid. Sure it's not supposed to be 'http://path'? Or are the server & port blank?

sblundy
+1  A: 

Your code works perfectly fine for me:

public static void main(String[] args) {
 try {
  java.net.URL connection_url = new java.net.URL("http://:/path");
  System.out.println("Instantiated new URL: " + connection_url);
 }
 catch (MalformedURLException e) {
  e.printStackTrace();
 }
}

Instantiated new URL: http://:/path

Sure you have the right line of code?

matt b