AsyncTask 在尝试使用 HtmlCleaner 清理 HTML 时不执行



我正在尝试使用AsyncTask使用HtmlCleaner清理HTML。这是代码:

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");
            Log.i("TAG", "Executing AsyncTask");
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
}

我正在onCreate方法中执行AsyncTask:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    new cleanHtml().execute();
}//End of onCreate

但是,什么也没发生。如您所见,我将log.i放在AsyncTask中以查看它是否正在执行,并且我从未在logcat中看到log.i消息。我可能做错了什么?另外,我的手机中会出现"清洁.xml"的位置?因为我没有设置任何类型的目标文件夹。

日志猫 (信息(:

09-25 20:23:31.739: W/System.err(19078): java.io.FileNotFoundException: /cleaned.xml: open failed: EROFS (Read-only file system)
09-25 20:23:31.747: W/System.err(19078):    at libcore.io.IoBridge.open(IoBridge.java:409)
09-25 20:23:31.747: W/System.err(19078):    at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
09-25 20:23:31.747: W/System.err(19078):    at java.io.FileOutputStream.<init>(FileOutputStream.java:128)
09-25 20:23:31.755: W/System.err(19078):    at java.io.FileOutputStream.<init>(FileOutputStream.java:117)
09-25 20:23:31.755: W/System.err(19078):    at org.htmlcleaner.Serializer.writeToFile(Serializer.java:131)
09-25 20:23:31.755: W/System.err(19078):    at org.htmlcleaner.Serializer.writeToFile(Serializer.java:142)
09-25 20:23:31.755: W/System.err(19078):    at com.whizzapps.stpsurniki.ScheudeleWithDesign$cleanHtml.doInBackground(ScheudeleWithDesign.java:36)
09-25 20:23:31.755: W/System.err(19078):    at com.whizzapps.stpsurniki.ScheudeleWithDesign$cleanHtml.doInBackground(ScheudeleWithDesign.java:1)
09-25 20:23:31.755: W/System.err(19078):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
09-25 20:23:31.755: W/System.err(19078):    at java.util.concurrent.FutureTask.run(FutureTask.java:234)
09-25 20:23:31.755: W/System.err(19078):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
09-25 20:23:31.755: W/System.err(19078):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
09-25 20:23:31.755: W/System.err(19078):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
09-25 20:23:31.755: W/System.err(19078):    at java.lang.Thread.run(Thread.java:841)
09-25 20:23:31.755: W/System.err(19078): Caused by: libcore.io.ErrnoException: open failed: EROFS (Read-only file system)
09-25 20:23:31.755: W/System.err(19078):    at libcore.io.Posix.open(Native Method)
09-25 20:23:31.755: W/System.err(19078):    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
09-25 20:23:31.763: W/System.err(19078):    at libcore.io.IoBridge.open(IoBridge.java:393)

执行 AsncTask。但是,由于例外情况,执行并没有结束。

您在此行中得到FileNotFoundEcxeption

 new PrettyXmlSerializer(props).writeToFile(node, "cleaned.xml", "utf-8");

它被您的捕获块捕获,防止您的应用程序崩溃。

异常可能是由以下原因引起的:

  • "已清理.xml"文件的路径不正确。
  • 文件名中的拼写错误。

相关内容

  • 没有找到相关文章

最新更新