2012-05-01 59 views
0

退出我得到一個錯誤,我不明白。我想要做的就是從pdf中提取文本。我使用droidText(http://code.google.com/p/droidtext/)這是代碼:螺紋與未捕獲的異常(組= 0x4001b188)

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()); 
     } 
    } 

}

這是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/[email protected]@[email protected] 
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. 

有誰知道什麼是錯我的代碼?

+0

你嘗試調試,並通過線步驟,看看哪一個可能會導致異常?引用看起來是有效的,只有「段落」變量可能會產生NullPointerException,但是您可能會在函數調用中獲得另一個類型。 – azertiti

+0

你是正確的錯誤來自paragraphs.add(scanner.nextLine()); 我收到同樣的錯誤,即使我嘗試 的System.out.println(scanner.nextLine()); 任何想法爲什麼? – user1366697

+0

在該語句周圍添加try catch部分,並查看您得到的異常。 – azertiti

回答

2

我與我的代碼相同的問題太多,於是我打開我的清單,發現有多個非必需的標籤,或者是雙申報或不關閉,糾正他們我的應用程序現在工作正常後。

這是我minifest以前

<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> 

,並做一些修正,現在看起來像這樣之後,如何看待

<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> 

每當有一個未捕獲線程異常就意味着有一個運行時間錯誤或更確切地說是程序流程中的錯誤。

如果這不起作用,請參閱 Uncaught handler: thread main exiting due to uncaught exception 其中還討論了關於線程。