gpt4 book ai didi

java - 在 JEditorPane 中打开 Web 链接时出错

转载 作者:行者123 更新时间:2023-11-30 11:30:54 25 4
gpt4 key购买 nike

我正在尝试在 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();
}
}

最佳答案

您的代码对我有用。您的 DNS 或代理设置可能有问题。

关于java - 在 JEditorPane 中打开 Web 链接时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17526324/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com