0

出于某种原因,我的代码不起作用。我已经在 中设置了适当的权限AndroidManifest.xml,但我没有得到任何结果。我对两者都很陌生jsoupAsyncTask所以我可能做错了什么。有谁知道这里发生了什么?

  public class Stuff extends AsyncTask<Void, Void, String> {
        TextView tv;
        String text = null;

        @Override
        protected String doInBackground(Void... arg0) {
            Document document;
            try {
                document = Jsoup.connect("http://www.google.com")
                        .userAgent("Mozilla").timeout(10000).get();

                Elements elements = document.select("a#gb_2");
                if (elements.size() > 0) {
                    text = elements.get(0).text();
                }
            } catch (IOException e) {
                text = "Error:" + e;
                e.printStackTrace();
            }
            return text;
        }

        protected void onPostExecute(String result) {
            tv = (TextView) findViewById(R.id.tv);
            tv.setText(text);

        }
    }
4

1 回答 1

0

我忘了执行Stuff()。哎呀。

于 2013-07-16T00:20:24.033 回答