0

I'm getting an error I don't understand. All I'm trying to do is extract text from a pdf. I'm using droidText (http://code.google.com/p/droidtext/) This is the code:

public void parsePdf(URL pdf) throws IOException {

    PdfReader reader = new PdfReader(pdf.openStream());
    PdfTextExtractor pdfEx = new PdfTextExtractor(reader);

    
    for(i=1; i <= reader.getNumberOfPages(); i++){
        Scanner scanner = new Scanner(pdfEx.getTextFromPage(i));
        while(scanner.hasNextLine()){
        paragraphs.add(scanner.nextLine());
        }
    }
    

}

This is the logcat:

05-01 17:04:37.059: D/dalvikvm(295): GC freed 4534 objects / 194136 bytes in 47ms
05-01 17:04:38.970: D/dalvikvm(295): GC freed 4416 objects / 411552 bytes in 62ms
05-01 17:04:38.980: I/dalvikvm-heap(295): Grow heap (frag case) to 5.906MB for 523658-byte allocation
05-01 17:04:39.049: D/dalvikvm(295): GC freed 334 objects / 15008 bytes in 64ms
05-01 17:04:39.371: D/dalvikvm(295): GC freed 504 objects / 284696 bytes in 50ms
05-01 17:04:39.380: I/dalvikvm-heap(295): Grow heap (frag case) to 6.625MB for 1054154-byte allocation
05-01 17:04:39.450: D/dalvikvm(295): GC freed 0 objects / 0 bytes in 74ms
05-01 17:04:39.520: D/dalvikvm(295): GC freed 1904 objects / 595384 bytes in 64ms
05-01 17:04:39.780: D/dalvikvm(295): GC freed 10610 objects / 1483240 bytes in 57ms
05-01 17:04:40.160: D/dalvikvm(295): GC freed 17834 objects / 808256 bytes in 62ms
05-01 17:04:40.610: D/dalvikvm(295): GC freed 20850 objects / 963048 bytes in 64ms 
05-01 17:04:41.090: D/dalvikvm(295): GC freed 30108 objects / 1060848 bytes in 67ms
05-01 17:04:41.210: D/AndroidRuntime(295): Shutting down VM
05-01 17:04:41.210: W/dalvikvm(295): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
05-01 17:04:41.220: E/AndroidRuntime(295): Uncaught handler: thread main exiting due to uncaught exception
05-01 17:04:41.334: I/DEBUG(27): *** *** *** *** *** *** *** *** *** *** *** *** ***  *** *** ***
05-01 17:04:41.334: I/DEBUG(27): Build fingerprint: 'generic/sdk/generic/:2.1-update1/ECLAIR/35983:eng/test-keys'
05-01 17:04:41.342: I/DEBUG(27): pid: 295, tid: 295  >>> com.android.horse <<<
05-01 17:04:41.342: I/DEBUG(27): signal 11 (SIGSEGV), fault addr 00000008
05-01 17:04:41.342: I/DEBUG(27):  r0 00000000  r1 beac7ae8  r2 4187033c  r3 00000000
05-01 17:04:41.342: I/DEBUG(27):  r4 beac7ae8  r5 4186be84  r6 beac7ae0  r7 40009ae8
05-01 17:04:41.342: I/DEBUG(27):  r8 ad00f380  r9 0000bd00  10 4186be58  fp 00000000
05-01 17:04:41.342: I/DEBUG(27):  ip 00000000  sp beac7a90  lr ad0544d3  pc ad034474  cpsr 40000030
05-01 17:04:41.400: I/DEBUG(27):          #00  pc 00034474  /system/lib/libdvm.so
05-01 17:04:41.400: I/DEBUG(27):          #01  pc 000544ce  /system/lib/libdvm.so
05-01 17:04:41.400: I/DEBUG(27):          #02  pc 00013f58  /system/lib/libdvm.so
05-01 17:04:41.411: I/DEBUG(27):          #03  pc 00019888  /system/lib/libdvm.so
05-01 17:04:41.411: I/DEBUG(27):          #04  pc 00018d5c  /system/lib/libdvm.so
05-01 17:04:41.411: I/DEBUG(27):          #05  pc 0004d6d0  /system/lib/libdvm.so
05-01 17:04:41.411: I/DEBUG(27):          #06  pc 0004d702  /system/lib/libdvm.so
05-01 17:04:41.411: I/DEBUG(27):          #07  pc 000404b8  /system/lib/libdvm.so
05-01 17:04:41.411: I/DEBUG(27):          #08  pc 00041334  /system/lib/libdvm.so
05-01 17:04:41.420: I/DEBUG(27):          #09  pc 00037e3a  /system/lib/libdvm.so
05-01 17:04:41.420: I/DEBUG(27):          #10  pc 00027a12  /system/lib/libdvm.so
05-01 17:04:41.420: I/DEBUG(27):          #11  pc 00027c7e  /system/lib/libandroid_runtime.so
05-01 17:04:41.420: I/DEBUG(27):          #12  pc 00008cae  /system/bin/app_process
05-01 17:04:41.420: I/DEBUG(27):          #13  pc 0000c2c6  /system/lib/libc.so
05-01 17:04:41.420: I/DEBUG(27):          #14  pc b00018aa  /system/bin/linker
05-01 17:04:41.430: I/DEBUG(27): code around pc:
05-01 17:04:41.430: I/DEBUG(27): ad034464 bdf0b011 0004bbfc 00000354 1c03b510 
05-01 17:04:41.430: I/DEBUG(27): ad034474 30106899 f7ff0849 bd10ff65 4d37b5f0 
05-01 17:04:41.430: I/DEBUG(27): ad034484 9100b083 1c16447d d0012a00 60132300 
05-01 17:04:41.430: I/DEBUG(27): code around lr:
05-01 17:04:41.430: I/DEBUG(27): ad0544c0 f86ef7ea 46c0bd10 6800b510 f7df1c0c 
05-01 17:04:41.430: I/DEBUG(27): ad0544d0 6020ffcf 46c0bd10 1c0cb510 fa8cf7ec 
05-01 17:04:41.430: I/DEBUG(27): ad0544e0 22002101 ffccf7df bd106020 1c03b510 
05-01 17:04:41.430: I/DEBUG(27): stack:
05-01 17:04:41.430: I/DEBUG(27):     beac7a50  0000bd00  [heap]
05-01 17:04:41.430: I/DEBUG(27):     beac7a54  00000012  
05-01 17:04:41.430: I/DEBUG(27):     beac7a58  00000000  
05-01 17:04:41.430: I/DEBUG(27):     beac7a5c  4506848e  /dev/ashmem/mspace/dalvik-heap/2 (deleted)
05-01 17:04:41.430: I/DEBUG(27):     beac7a60  00000001  
05-01 17:04:41.430: I/DEBUG(27):     beac7a64  ad054403  /system/lib/libdvm.so
05-01 17:04:41.430: I/DEBUG(27):     beac7a68  00000001  
05-01 17:04:41.430: I/DEBUG(27):     beac7a6c  0005c368  [heap]
05-01 17:04:41.430: I/DEBUG(27):     beac7a70  00000000  
05-01 17:04:41.430: I/DEBUG(27):     beac7a74  00000001  
05-01 17:04:41.430: I/DEBUG(27):     beac7a78  000007ab  
05-01 17:04:41.430: I/DEBUG(27):     beac7a7c  00000001  
05-01 17:04:41.440: I/DEBUG(27):     beac7a80  afe0df40  /system/lib/libc.so
05-01 17:04:41.440: I/DEBUG(27):     beac7a84  00000001  
05-01 17:04:41.440: I/DEBUG(27):     beac7a88  df002777  
05-01 17:04:41.440: I/DEBUG(27):     beac7a8c  e3a070ad  
05-01 17:04:41.440: I/DEBUG(27): #00 beac7a90  beac7ae8  [stack]
05-01 17:04:41.440: I/DEBUG(27):     beac7a94  ad0544d3  /system/lib/libdvm.so
05-01 17:04:41.440: I/DEBUG(27): #01 beac7a98  41f7c228  /data/dalvik-cache/system@framework@core.jar@classes.dex
05-01 17:04:41.440: I/DEBUG(27):     beac7a9c  ad013f5c  /system/lib/libdvm.so
05-01 17:04:41.790: D/Zygote(29): Process 295 terminated by signal (11)
05-01 17:04:41.790: I/WindowManager(51): WIN DEATH: Window{44df4c38 com.android.horse/com.android.horse.HorseEdgeActivity paused=false}
05-01 17:04:41.790: I/ActivityManager(51): Process com.android.horse (pid 295) has died.

Does anyone know what's is wrong with my code?

Community
  • 1
  • 1
user1366697
  • 171
  • 2
  • 9
  • Did you try to debug and step through the lines to see which one might cause an exception ? The references look valid, only "paragraphs" variable could make a NullPointerException but you might get another type in a function call. – azertiti May 01 '12 at 17:57
  • You are correct the error comes from paragraphs.add(scanner.nextLine()); I receive the same error even if I try System.out.println(scanner.nextLine()); Any idea why? – user1366697 May 01 '12 at 18:26
  • Add a try catch section around that statement and see what exception you get. – azertiti May 01 '12 at 18:35
  • UnsupportedEncodingException :\ apparently MacRoman – user1366697 May 01 '12 at 18:48
  • nextLine from Scanner can't throw that exception. My guess is you get it when adding the line to "paragraph" object. This is the direction you must investigate further. – azertiti May 01 '12 at 18:57
  • 1
    You can provide your own Charset provider as described here: http://developer.android.com/reference/java/nio/charset/Charset.html. If you don't wanna write one yourself you can find one for MacRoman from the GNU classpath project http://www.doc.ic.ac.uk/~awl03/cgi-bin/trac.cgi/miro/browser/trunk/gcc/libjava/classpath/gnu/java/nio/charset/MacRoman.java –  Jul 07 '12 at 18:10

1 Answers1

2

I had the same problem with my code too, Then I opened my manifest and found that there were multiple non required tags, which are either double declared or non closed, after correcting them my app works properly now.

This is how my minifest looked previously

    <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
     <intent-filter >
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
        </intent-filter>

            </intent-filter>
    </activity>

    <activity android:name=".SecondActivity"/>
    <activity android:name=".ThirdActivity"/>
    <activity android:name=".FourthActivity"/>
    <activity android:name=".FifthActivity"/>
    <activity android:name=".SixthActivity"/>
    <activity android:name=".SeventhActivity"/>

    </application>

and after making some corrections it looks like this now,

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="my.project.mil"
           android:versionCode="1"
           android:versionName="1.0" >

    <uses-sdk
           android:minSdkVersion="5"
           android:targetSdkVersion="15" />

    <application
           android:icon="@drawable/ic_launcher"
           android:label="@string/app_name"
           android:theme="@style/AppTheme" >
    <activity
           android:name=".MainActivity"
           android:label="@string/title_activity_main" >
    <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />

            <action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
    </intent-filter>
    </activity>   


    <activity android:name=".SecondActivity"/>
    <activity android:name=".ThirdActivity"/>
    <activity android:name=".FourthActivity"/>
    <activity android:name=".FifthActivity"/>
    <activity android:name=".SixthActivity"/>
    <activity android:name=".SeventhActivity"/>


   </application>

  </manifest>

Whenever there is an uncaught thread exception it means that there is a run time error or to be more precise an error in the flow of the program.

if this doesn't work, refer Uncaught handler: thread main exiting due to uncaught exception which also discusses about threads.

Community
  • 1
  • 1