【问题标题】:Cleaning HTML with HtmlCleaner and AsyncTask使用 HtmlCleaner 和 AsyncTask 清理 HTML
【发布时间】:2013-09-25 16:08:40
【问题描述】:

我正在尝试获取一个干净的 XML 文件,以便我可以解析数据。这是我的尝试:

private class cleanHtml extends AsyncTask<Void, Void, Void>{

    @Override
    protected Void doInBackground(Void... arg0) {
        try {
            HtmlCleaner cleaner = new HtmlCleaner();
            String url = "https://www.easistent.com/urniki/263/razredi/16515";
            TagNode node = cleaner.clean(new URL(url));
            CleanerProperties props = cleaner.getProperties();
            new PrettyXmlSerializer(props).writeToFile(node, "cleaned.xml", "utf-8");
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
}

我必须使用 AsyncTask,因为如果我在主 UI 上使用它会导致应用崩溃。

现在这就是我尝试执行此操作的方式:

cleanHtml.execute();

但是,这不起作用。它强调了“cleanHtml.execute();”并说:

无法从 AsyncTask 类型对非静态方法 execute(Void...) 进行静态引用

知道我现在如何运行这个 AsyncTask 吗?我做得对吗?另外,一旦我得到这个工作,我在哪里可以看到输出cleaned.xml文件?由于我没有设置任何“输出文件夹”。

【问题讨论】:

    标签: java android android-asynctask htmlcleaner


    【解决方案1】:

    使用

    new cleanHtml.execute();
    

    而不是

    cleanHtml.execute();
    

    用于执行AsyncTask,因为execute() 不是AsyncTask 类的静态方法,所以您需要创建类的实例来调用execute() 方法

    【讨论】:

      猜你喜欢
      • 2013-10-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-25
      • 2011-11-03
      • 1970-01-01
      • 1970-01-01
      • 2012-07-15
      • 1970-01-01
      相关资源
      最近更新 更多