6

I am currently calling the following line of code:

java.net.URL connection_url = new java.net.URL("http://<ip address>:<port>/path");

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

2
  • I'm not getting that same exception with the exact same code. Commented Sep 12, 2008 at 20:21
  • What version of Java is causing the exception? Commented Sep 13, 2008 at 0:08

5 Answers 5

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

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: symphonious.net/2007/03/29/javaneturl-or-javaneturi
You probably don't want to use java.net.URI if you're working with URLs as found in the wild (often invalid URIs).
2

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?

Comments

2

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

1 Comment

Thanks! that worked for me. Had missed adding the protocol before the IP address. I guess Chrome has spoiled me :)
1

I have also had the same exception, but in my case the URL which I was trying to execute had a space appended. After removing the space it worked fine for me. Check that the URL does not have any trailing spaces in your case.

Comments

1

I had the same error and it got resolved by the below :

The jar files (JFree) which I added few days back got corrupted automatically and was causing this error. I downloaded the same files again from net and it worked fine for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.