Getting java exception: java.net.MalformedURLException: no protocol

I am currently invoking 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 is executed. Any ideas as to why this is happening?

+5
source share
5 answers

Your code works 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();
    }
}

New URL created: http: //: / path

Do you have the correct line of code?

+2
source

As a side note, you should use URIs because the Java URL class is confusing. (I assume the method is equal)

+4
source

url . , http://path '? ?

+2

I also had the same exception, but in my case, the URL that I was trying to execute took place. After removing the space, it worked perfectly for me. Make sure your URL does not have trailing spaces.

+1
source

I had the same error and it was solved as follows:

The jar (JFree) files that I added a few days ago were corrupted automatically and caused this error. I downloaded the same files from the network again, and it worked fine for me.

+1
source

All Articles