gpt4 book ai didi

java - 尝试使用 HtmlCleaner 清理 HTML 时,AsyncTask 不执行

转载 作者:行者123 更新时间:2023-12-01 04:20:12 25 4
gpt4 key购买 nike

我正在尝试使用 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 消息。我可能做错了什么?另外,“cleaned.xml”会出现在我的手机中的什么位置?因为我没有设置任何类型的目标文件夹。

Logcat(信息):

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 已执行。但执行并未因异常而结束。

您在此行中收到 FileNotFoundExption:

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

它被你的 catch-block 捕获,防止你的应用程序崩溃。

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

  • “cleaned.xml”文件的路径不正确。
  • 文件名拼写错误。

关于java - 尝试使用 HtmlCleaner 清理 HTML 时,AsyncTask 不执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19010295/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com