javax.xml.parsers.ParserConfigurationException
I tried to use the library according to the guideline on the GitHub page The first problem I got is that there is no class called Book.
The fifth line of code in the Usage section tries to create a Book object from reader.readSection. I thought maybe you meant to say BookSection so I replaced it.
And further into the code reader.setFullContent(epubFilePath); throws the following exception. (I have put the complete stack trace)
What I understood while debugging is that the DocumentBuilderFactoryImpl class throws ParserConfigurationException if instance of DocumentBuilderFactoryImpl calls setFeature with names different from http://xml.org/sax/features/namespaces and http://xml.org/sax/features/validation
Is there a problem with my android depedencies?
javax.xml.parsers.ParserConfigurationException: http://apache.org/xml/features/nonvalidating/load-dtd-grammar
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at org.apache.harmony.xml.parsers.DocumentBuilderFactoryImpl.setFeature(DocumentBuilderFactoryImpl.java:101)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at com.github.mertakdut.Reader.fillContent(Reader.java:98)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at com.github.mertakdut.Reader.setFullContent(Reader.java:39)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at com.a360ground.lomibooksrecycler.BookReaderActivity.onCreate(BookReaderActivity.java:31)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at android.app.Activity.performCreate(Activity.java:6178)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2648)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at android.app.ActivityThread.access$900(ActivityThread.java:177)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1430)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at android.os.Looper.loop(Looper.java:135)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5910)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at java.lang.reflect.Method.invoke(Native Method)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at java.lang.reflect.Method.invoke(Method.java:372)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
Hello,
-
Yes, i had a misstyping in usage section, corrected it now. Thank you.
-
I came across in unit tests, parsing some xml files was taking too long, because of the validations. So I disabled the validations (related answer). It works perfectly fine in my unit tests; but getting the same exceptions in Sample Application as well. Though it didn't occur to me that the exceptions breaks the operation of the library.
I'll dig in for more info.
Android sdk (api-23) uses this method for setFeature:
`@Override
public void setFeature(String name, boolean value)
throws ParserConfigurationException {
if (name == null) {
throw new NullPointerException("name == null");
}
if (NAMESPACES.equals(name)) {
setNamespaceAware(value);
} else if (VALIDATION.equals(name)) {
setValidating(value);
} else {
throw new ParserConfigurationException(name);
}
}`
As this states, android throws exception for all other features other than namespace and validation.
Same problem here. Get a ParserConfigurationException on reader.setFullContent(epubFilePath). The Exception doesn't break the operation and I can get the ebook content with bookSection.getSectionContent().
I'm getting the same error with the sample app provided EpubParser-Sample-Android-Application.
It looks like Android SDK DocumentBuilderFactory cannot support these two features
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
As these features are used for document validation maybe they are not mandatory ? anyway they are not supported on API 25. docs here and here