Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.net.MalformedURLException: no protocol

843834Feb 19 2008 — edited Feb 21 2008
Hi,

I'm trying to parse an html website to a w3c document, but I'm getting the following exception:
java.net.MalformedURLException: no protocol

The code is:
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

.
.
.

        URL u; 
        InputStream is = null; 
        DataInputStream dis; 
        String s;
        StringBuffer xmlFeed = new StringBuffer();

        try {
            u = new URL("http://www.google.com"); 
            is = u.openStream(); 
            dis = new DataInputStream(new BufferedInputStream(is)); 
            while ((s = dis.readLine()) != null) {
                 xmlFeed.append(s);
         } catch (Exception ex) {
               System.out.println("no good");
         }

// So far so good.....

        try {
	DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
	docBuilderFactory.setIgnoringComments(true);
	docBuilderFactory.setValidating(false);
	DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
	Document doc = docBuilder.parse(xmlFeed.toString());  // The exception is caught here.....
          } catch (Exception ex) {
   	  System.out.println(ex.getMessage());
          }
Can anyone offer some assistance?

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 20 2008
Added on Feb 19 2008
4 comments
733 views