I'm trying to clean HTML with HtmlCleaner using AsyncTask. This is the code:
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;
}
}
I'm executing AsyncTask in onCreate method:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new cleanHtml().execute();
}//End of onCreate
However, nothing happens. As you can see I put log.i inside the AsyncTask to see if it is executing r not and I never see the log.i message inside logcat. What could I be doing wrong? Also, where in my phone will "cleaned.xml" appear? Since I didn't set any kind of destination folder.
Logcat (info):
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)
The AsncTask is executed. But the execution is not brought to an end because of an exception.
You are getting a FileNotFoundEcxeption
in this line:
new PrettyXmlSerializer(props).writeToFile(node, "cleaned.xml", "utf-8");
which is caught by your catch-block preventing your app from crashing.
The Exception could be caused by: