Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

java problem

  • 28-01-2005 08:29PM
    #1
    Registered Users, Registered Users 2 Posts: 3,548 ✭✭✭


    Im trying to write a simple program to connect to a website using URL objects. However, im constantly getting this UnknownHostException. Anything Ive read regarding this so far seems to talk about proxys, but I dont use one!

    Anyone know whats going on?

    Heres my simple code:

    import java.io.*;
    import java.net.*;

    class Tester
    {
    public static void main(String[] args)
    {
    try {
    URL yahoo = new URL("http://www.yahoo.com");
    URLConnection yc = yahoo.openConnection();

    BufferedReader in = new BufferedReader(
    new InputStreamReader(
    yc.getInputStream()));


    }catch (UnknownHostException e) { e.printStackTrace(); // new URL() failed

    } catch (MalformedURLException e) { e.printStackTrace(); // new URL() failed

    } catch (IOException e) { e.printStackTrace(); // openConnection() failed

    }
    System.out.println("Done");
    }
    }


Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Compiling and running fine for me... Even wrote a loop into it to print the HTML to the console...


  • Registered Users, Registered Users 2 Posts: 3,548 ✭✭✭Draupnir


    just doesnt make sense, heres the error I get:

    E:\NationalAssistant>java Tester
    java.net.UnknownHostException: www.yahoo.com
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.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.http.HttpClient.<init>(Unknown Source)
    at sun.net.www.http.HttpClient.New(Unknown Source)
    at sun.net.www.http.HttpClient.New(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown
    Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Sour
    ce)
    at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown So
    urce)
    at Tester.main(Tester.java:12)
    Done


  • Registered Users, Registered Users 2 Posts: 240 ✭✭Manchegan


    Uh... try being connected to the Intarweb ;)


  • Registered Users, Registered Users 2 Posts: 2,243 ✭✭✭zoro


    I THINK you need "http://&quot; in front of it.


  • Registered Users, Registered Users 2 Posts: 261 ✭✭HaVoC


    might be the problem described here
    under the heading "A More Serious Issue"


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 3,548 ✭✭✭Draupnir


    yeah I was connected to the Internet and I also had http in front of it thanks Dan! Got the program running by using my laptop. I only get that eror on my desktop for whatever strange reason, even though im connecting both to the same router.


  • Registered Users, Registered Users 2 Posts: 2,243 ✭✭✭zoro


    How do you know me? :)


  • Registered Users, Registered Users 2 Posts: 3,548 ✭✭✭Draupnir


    Tis me, the former owner of RimLand, one half of the Redmond - Winders double act.


  • Registered Users, Registered Users 2 Posts: 2,243 ✭✭✭zoro


    Ah I see! Well - you can ask for help any time :)


Advertisement