javaandroidandroid-asynctaskhtmlcleaner

Cleaning HTML with HtmlCleaner and AsyncTask


I'm trying to get a cleaned XML file so that I can parse data. This is my attempt:

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;
    }
}

I had to use AsyncTask since the app crashed if I did it on Main UI.

And now this is how I'm trying to execute this:

cleanHtml.execute();

However, this doesn't work. It underlines the "cleanHtml.execute();" and says this:

Cannot make a static reference to the non-static method execute(Void...) from the type AsyncTask

Any idea how can I run this AsyncTask now? Am I even doing it right? Also, once I get this working, where will I be able to see the output cleaned.xml file? Since I didn't set any "output folder".


Solution

  • use

    new cleanHtml.execute();
    

    instead of

    cleanHtml.execute();
    

    for executing AsyncTask because execute() is not static method of AsyncTask class so you will need to create instance of class for calling execute() method