doosungkang / android-daisy-epub-reader

Automatically exported from code.google.com/p/android-daisy-epub-reader
0 stars 0 forks source link

DaisyReader crashes during search for books with XML Parser error when a book has an unknown encoding #61

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Have a book on the SD Card with an 'unknown' encoding - one the app / the 
SAX doesn't know how to parse. 
2. Use the 'Search for Books' button to find books on the SD Card.

What is the expected output? 
- The app should present the user with a list of the recognised DAISY 2.02 
format books. The app should not crash :)

What do you see instead?
The app crashes and quits.

Note: There are 2 issues to address:
   1. Discovering why a particular book isn't parsed correctly
   2. Catching the runtime exception programatically and presenting a friendly, useful, and actionable message to the user instead of crashing.

Logcat contains the following output

I/DaisyBookFinder(31007): onCreate
I/DaisyBookFinder(31007): The root folder to search is: /sdcard/daisy/
I/BookValidator(31007): Book available at : /sdcard/daisy/unpacked/class6hindi
I/BookValidator(31007): Book available at : 
/sdcard/daisy/unpacked/japan/Bangumi 202 audio NCC NHK11
I/BookValidator(31007): Book available at : 
/sdcard/daisy/unpacked/japan/gon-ruby-mp3 2.02 full text full audio
I/BookValidator(31007): Book available at : /sdcard/daisy/unpacked/Andrija 
Nikolic - Ziva hrana kao lijek
I/BookValidator(31007): Book available at : /sdcard/daisy/unpacked/norvay/2.02 
full text full audio
I/BookValidator(31007): Book available at : /sdcard/daisy/unpacked/norvay/2.02 
ncc audio
I/DaisyBookFinder(31007): External Storage is: /mnt/sdcard
I/DaisyBookImplementation(31007): /
I/DaisyParser(31007): XMLFILE /sdcard/daisy/unpacked/class6hindi/ncc.html
D/dalvikvm(31007): GC_CONCURRENT freed 228K, 3% free 12851K/13127K, paused 
2ms+2ms
I/DaisyBookImplementation(31007): /
I/DaisyParser(31007): XMLFILE /sdcard/daisy/unpacked/japan/Bangumi 202 audio 
NCC NHK11/ncc.html
D/AndroidRuntime(31007): Shutting down VM
W/dalvikvm(31007): threadid=1: thread exiting with uncaught exception 
(group=0x40a311f8)
E/AndroidRuntime(31007): FATAL EXCEPTION: main
E/AndroidRuntime(31007): java.lang.RuntimeException: Unable to start activity 
ComponentInfo{com.ader/com.ader.ui.DaisyBookFinder}: j
ava.lang.RuntimeException: org.apache.harmony.xml.ExpatParser$ParseException: 
At line 1, column 0: unknown encoding
E/AndroidRuntime(31007):        at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
E/AndroidRuntime(31007):        at 
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
E/AndroidRuntime(31007):        at 
android.app.ActivityThread.access$600(ActivityThread.java:123)
E/AndroidRuntime(31007):        at 
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
E/AndroidRuntime(31007):        at 
android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(31007):        at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(31007):        at 
android.app.ActivityThread.main(ActivityThread.java:4424)
E/AndroidRuntime(31007):        at java.lang.reflect.Method.invokeNative(Native 
Method)
E/AndroidRuntime(31007):        at 
java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(31007):        at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime(31007):        at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime(31007):        at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(31007): Caused by: java.lang.RuntimeException: 
org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column
 0: unknown encoding
E/AndroidRuntime(31007):        at 
com.ader.DaisyParser.parseNccContents(DaisyParser.java:146)
E/AndroidRuntime(31007):        at 
com.ader.DaisyParser.openAndParseFromFile(DaisyParser.java:67)
E/AndroidRuntime(31007):        at 
com.ader.OldDaisyBookImplementation.openFromFile(OldDaisyBookImplementation.java
:123)
E/AndroidRuntime(31007):        at 
com.ader.ui.DaisyBookFinder.populateList(DaisyBookFinder.java:92)
E/AndroidRuntime(31007):        at 
com.ader.ui.DaisyBookFinder.onCreate(DaisyBookFinder.java:48)
E/AndroidRuntime(31007):        at 
android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime(31007):        at 
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
E/AndroidRuntime(31007):        at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
E/AndroidRuntime(31007):        ... 11 more
E/AndroidRuntime(31007): Caused by: 
org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: unknown 
encoding
E/AndroidRuntime(31007):        at 
org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:515)
E/AndroidRuntime(31007):        at 
org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:474)
E/AndroidRuntime(31007):        at 
org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:321)
E/AndroidRuntime(31007):        at 
org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:279)
E/AndroidRuntime(31007):        at 
com.ader.DaisyParser.parseNccContents(DaisyParser.java:142)
E/AndroidRuntime(31007):        ... 18 more
W/ActivityManager(  191):   Force finishing activity 
com.ader/.ui.DaisyBookFinder
W/ActivityManager(  191):   Force finishing activity com.ader/.ui.HomeScreen
D/dalvikvm(31007): GC_CONCURRENT freed 136K, 2% free 13250K/13447K, paused 
2ms+17ms
W/ActivityManager(  191): Activity pause timeout for ActivityRecord{41efdc30 
com.ader/.ui.DaisyBookFinder}
D/dalvikvm(  486): GC_CONCURRENT freed 3738K, 26% free 20592K/27463K, paused 
4ms+3ms
D/dalvikvm(  486): GC_FOR_ALLOC freed 396K, 25% free 20735K/27463K, paused 48ms
I/ActivityManager(  191): No longer want com.android.voicedialer (pid 30472): 
hidden #16
D/dalvikvm(  486): GC_CONCURRENT freed 8K, 18% free 22664K/27463K, paused 
11ms+6ms
I/Process (31007): Sending signal. PID: 31007 SIG: 9
I/ActivityManager(  191): Process com.ader (pid 31007) has died.
I/WindowManager(  191): WIN DEATH: Window{419e3b50 
com.ader/com.ader.ui.HomeScreen paused=true}
W/ActivityManager(  191): Activity destroy timeout for ActivityRecord{41ee68a8 
com.ader/.ui.HomeScreen}
W/ActivityManager(  191): Activity destroy timeout for ActivityRecord{41efdc30 
com.ader/.ui.DaisyBookFinder}

Original issue reported on code.google.com by julianharty on 18 May 2012 at 2:41

GoogleCodeExporter commented 8 years ago
I have applied a minimal fix to the existing DaisyReader so at least the app 
doesn't crash when the underlying SAX parser complains by raising an exception 
when it is unable to process the ncc file for a book. The problem happens when 
the SAX parser encounters Shift_JIS encoding in ncc.html (and probably also 
happens for other files). I'll now investigate how to convince SAX to parse 
Shift_JIS files on Android.

Original comment by julianharty on 21 Oct 2012 at 8:56

GoogleCodeExporter commented 8 years ago
Here are a bunch of links that might help me to resolve the problem when I have 
the energy to work on a problem that's rare for users of this app AFAIK

http://stackoverflow.com/questions/11544713/utf-8-and-sjis-problems-on-android-a
nd-sockets 
The following looks interesting 
http://www.coderanch.com/t/450324/java/java/parsing-Japanese-SHIFT-JIS-Character
s

http://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/CharsetDecoder.htm
l#decode(java.nio.ByteBuffer, java.nio.CharBuffer, boolean)

If in doubt perhaps we can replace the parser for a generic Java implementation?
http://xerces.apache.org/xerces2-j/faq-general.html

Original comment by julianharty on 17 Jan 2013 at 7:51