2013-07-08 33 views
2
打開網絡鏈接

我試圖打開的JEditorPane一個鏈接,但我得到的下跌錯誤錯誤而在JEditorPane中

**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 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 Source) 
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source) 
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) 
at java.net.HttpURLConnection.getResponseCode(Unknown Source) 
at javax.swing.JEditorPane.getStream(Unknown Source) 
at javax.swing.JEditorPane.setPage(Unknown Source) 
at javax.swing.JEditorPane.setPage(Unknown Source) 
at javax.swing.JEditorPane.<init>(Unknown Source) 
at GetWebPage.main(GetWebPage.java:7)** 
下面

是我的代碼

import javax.swing.JEditorPane; 
import javax.swing.JFrame; 
import javax.swing.JScrollPane; 

public class GetWebPage { 

    public static void main(String args[]) throws Exception { 

     JEditorPane website = new JEditorPane("http://www.google.com/"); 
     website.setEditable(false); 

     JFrame frame = new JFrame("Google"); 
     frame.add(new JScrollPane(website)); 
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     frame.setVisible(true); 
     frame.pack(); 
    } 
} 
+0

代碼在我身邊正常工作,請檢查您的互聯網設置... –

+0

檢查代理設置,如果你代理 – Optional

+0

哦,我看到讓我檢查然後 –

回答

1

您的代碼對我的作品。您的DNS或代理設置可能存在問題。

+0

謝謝你會檢查 –

+0

我如何設置代碼中的代理? –

+0

@JavaNoob http://stackoverflow.com/questions/120797/how-do-i-set-the-proxy-to-be-used-by-the-jvm –