Android JSoup 连接问题

发布于 2024-11-14 15:47:49 字数 487 浏览 8 评论 0原文

使用 JSoup 网站上的指南,我编写了以下代码:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
        Document doc = Jsoup.connect("http://google.com").get();
        Elements links = doc.getElementsByTag("a");
        for(Element ele : links){
            Log.i("Menu", ele.text());
        }
    } catch (IOException e) {

    }
    setContentView(R.layout.main);
}

我在清单文件中添加了互联网权限,但它不断抛出 IOException!

Using the guide on JSoup's website I wrote the following code:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
        Document doc = Jsoup.connect("http://google.com").get();
        Elements links = doc.getElementsByTag("a");
        for(Element ele : links){
            Log.i("Menu", ele.text());
        }
    } catch (IOException e) {

    }
    setContentView(R.layout.main);
}

I added the internet permission in my manifest file but it keeps throwing an IOException!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

春夜浅 2024-11-21 15:47:49

我测试了你的代码,它应该可以正常工作......我想你的许可被放在了错误的位置。它位于清单中的应用程序定义之前:

以下是运行您的代码的清单的前几行:

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

<application android:icon="@drawable/icon" android:label="@string/app_name">

I tested your code and it should work fine... I would imagine your permission was put in the wrong spot. It goes BEFORE your application definition in your manifest:

here are the first few lines of my manifest that runs your code:

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

<application android:icon="@drawable/icon" android:label="@string/app_name">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文