This discussion is archived
3 Replies Latest reply: Feb 12, 2013 4:58 AM by BIJ001 RSS

Unknown host excpetion

Raja_236 Newbie
Currently Being Moderated
Hi,

am getting below unknown exception while execution below code. Please suggest how to get rid of this exception.
mport java.io.InputStreamReader;
import java.net.URL;

class Mainclass3
{
     public static void main(String[] args) throws Exception 
     {
       System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");

        URL url = new URL ("https://www.google.com/");
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String line;
        while ((line = in.readLine()) != null)

        {
             System.out.println(line);
        }
        in.close();

     }
}
Exception details
Exception in thread "main" java.net.UnknownHostException: www.google.com
        at java.net.PlainSocketImpl.connect(Unknown Source)
        at java.net.SocksSocketImpl.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(Unknown Source)
        at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(Unknown Source)
        at sun.net.NetworkClient.doConnect(Unknown Source)
        at sun.net.www.http.HttpClient.openServer(Unknown Source)
        at sun.net.www.http.HttpClient.openServer(Unknown Source)
        at sun.net.www.protocol.https.HttpsClient.<init>(Unknown Source)
        at sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
        at com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl.getInputStream(Unknown Source)
        at java.net.URL.openStream(Unknown Source)
        at Mainclass3.main(Mainclass3.java:12)
thanks in advance
  • 1. Re: Unknown host excpetion
    EJP Guru
    Currently Being Moderated
    System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
    Slightly off topic, but you haven't needed that line of code since about 2003.

    Can you ping www.google.com from a command prompt? If not, you have a DNS problem, nothing to do with Java.
  • 2. Re: Unknown host excpetion
    Raja_236 Newbie
    Currently Being Moderated
    System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
    
    -----Slightly off topic, but you haven't needed that line of code since about 2003.
    what type statement i need to use here instead of above mentioned code line.

    Can you ping www.google.com from a command prompt? If not, you have a DNS problem, nothing to do with Java

    am unable to ping the site, please suggest howto resolve this .

     D:\Documents and Settings\ba80123524>ping https://www.google.com
    Ping request could not find host https://www.google.com. Please check the name and try again
  • 3. Re: Unknown host excpetion
    BIJ001 Explorer
    Currently Being Moderated
    A sidenote: you ping a site, not a URL, that is, you rather ping www.google.com than https://www.google.com.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points