4

得到错误

E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
       java.lang.RuntimeException: An error occured while executing doInBackground()
           at android.os.AsyncTask$3.done(AsyncTask.java:299)
           at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
           at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
           at java.util.concurrent.FutureTask.run(FutureTask.java:239)
           at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
           at java.lang.Thread.run(Thread.java:856)
        Caused by: java.lang.ExceptionInInitializerError
           at b.b.a.c.c.p.<init>(HSSFWorkbook.java:326)
           at b.b.a.c.c.p.<init>(HSSFWorkbook.java:289)
           at b.b.a.c.c.p.<init>(HSSFWorkbook.java:224)
           at b.b.a.c.c.p.<init>(HSSFWorkbook.java:382)
           at b.b.a.c.c.p.<init>(HSSFWorkbook.java:364)
           at com.d.link.d.d.a(ExportUtils.java:134)
           at com.d.link.activity.ey.a(SplashScreen.java:55)
           at com.d.link.activity.ey.doInBackground(SplashScreen.java:51)
           at android.os.AsyncTask$2.call(AsyncTask.java:287)
           at java.util.concurrent.FutureTask.run(FutureTask.java:234)
           at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 
           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
           at java.lang.Thread.run(Thread.java:856) 
        Caused by: b.b.a.c.b.dj: Unable to determine record types
           at b.b.a.c.b.dd.a(RecordFactory.java:434)
           at b.b.a.c.b.dd.<clinit>(RecordFactory.java:292)
           at b.b.a.c.c.p.<init>(HSSFWorkbook.java:326) 
           at b.b.a.c.c.p.<init>(HSSFWorkbook.java:289) 
           at b.b.a.c.c.p.<init>(HSSFWorkbook.java:224) 
           at b.b.a.c.c.p.<init>(HSSFWorkbook.java:382) 
           at b.b.a.c.c.p.<init>(HSSFWorkbook.java:364) 
           at com.d.link.d.d.a(ExportUtils.java:134) 
           at com.d.link.activity.ey.a(SplashScreen.java:55) 
           at com.d.link.activity.ey.doInBackground(SplashScreen.java:51) 
           at android.os.AsyncTask$2.call(AsyncTask.java:287) 
           at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
           at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 
           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
           at java.lang.Thread.run(Thread.java:856) 

 

对于第二行(来自 InputStream 的新 HSSFWorkbook) FileInputStream fileInS = new FileInputStream(outputXlsFile); hwb = new HSSFWorkbook(fileInS);

apachePoi 库org.apache.poi.hssf.usermodel.HSSFWorkbook在哪里

4

4 回答 4

5

Excel 记录

在数据库术语中,记录包含有关已输入数据库的特定对象的所有信息或数据。在 Excel 中,记录通常组织在工作表行中,行中的每个单元格都包含一项信息或值。

基于 RecordFactory 的代码

http://www.docjar.com/html/api/org/apache/poi/hssf/record/RecordFactory.java.html

看起来您获得了一些与您拥有的 poi 版本不兼容的对象(在本例中为记录)。看起来您的记录不是 RecordFactory 中指定的任何类型。因此,您应该检查在服务器端如何创建这些文件以及与记录相关的代码。或者,如果它们是手动创建的,您应该检查 Excel 或 Open Office 版本,查看它们支持的记录类型,并将它们与您在 Android 设备上使用的库进行比较。

private static final Class<? extends Record>[] recordClasses = new Class[] {
   81           ArrayRecord.class,
   82           BackupRecord.class,
   83           BlankRecord.class,
   84           BOFRecord.class,
   85           BookBoolRecord.class,
   86           BoolErrRecord.class,
   87           BottomMarginRecord.class,
   88           BoundSheetRecord.class,
   89           CalcCountRecord.class,
   90           CalcModeRecord.class,
   91           CFHeaderRecord.class,
   92           CFRuleRecord.class,
   93           ChartRecord.class,
   94           ChartTitleFormatRecord.class,
   95           CodepageRecord.class,
   96           ColumnInfoRecord.class,
   97           ContinueRecord.class,
   98           CountryRecord.class,
   99           CRNCountRecord.class,
  100           CRNRecord.class,
  101           DateWindow1904Record.class,
  102           DBCellRecord.class,
  103           DefaultColWidthRecord.class,
  104           DefaultRowHeightRecord.class,
  105           DeltaRecord.class,
  106           DimensionsRecord.class,
  107           DrawingGroupRecord.class,
  108           DrawingRecord.class,
  109           DrawingSelectionRecord.class,
  110           DSFRecord.class,
  111           DVALRecord.class,
  112           DVRecord.class,
  113           EOFRecord.class,
  114           ExtendedFormatRecord.class,
  115           ExternalNameRecord.class,
  116           ExternSheetRecord.class,
  117           ExtSSTRecord.class,
  118           FilePassRecord.class,
  119           FileSharingRecord.class,
  120           FnGroupCountRecord.class,
  121           FontRecord.class,
  122           FooterRecord.class,
  123           FormatRecord.class,
  124           FormulaRecord.class,
  125           GridsetRecord.class,
  126           GutsRecord.class,
  127           HCenterRecord.class,
  128           HeaderRecord.class,
  129           HideObjRecord.class,
  130           HorizontalPageBreakRecord.class,
  131           HyperlinkRecord.class,
  132           IndexRecord.class,
  133           InterfaceEndRecord.class,
  134           InterfaceHdrRecord.class,
  135           IterationRecord.class,
  136           LabelRecord.class,
  137           LabelSSTRecord.class,
  138           LeftMarginRecord.class,
  139           LegendRecord.class,
  140           MergeCellsRecord.class,
  141           MMSRecord.class,
  142           MulBlankRecord.class,
  143           MulRKRecord.class,
  144           NameRecord.class,
  145           NoteRecord.class,
  146           NumberRecord.class,
  147           ObjectProtectRecord.class,
  148           ObjRecord.class,
  149           PaletteRecord.class,
  150           PaneRecord.class,
  151           PasswordRecord.class,
  152           PasswordRev4Record.class,
  153           PrecisionRecord.class,
  154           PrintGridlinesRecord.class,
  155           PrintHeadersRecord.class,
  156           PrintSetupRecord.class,
  157           ProtectionRev4Record.class,
  158           ProtectRecord.class,
  159           RecalcIdRecord.class,
  160           RefModeRecord.class,
  161           RefreshAllRecord.class,
  162           RightMarginRecord.class,
  163           RKRecord.class,
  164           RowRecord.class,
  165           SaveRecalcRecord.class,
  166           ScenarioProtectRecord.class,
  167           SelectionRecord.class,
  168           SeriesRecord.class,
  169           SeriesTextRecord.class,
  170           SharedFormulaRecord.class,
  171           SSTRecord.class,
  172           StringRecord.class,
  173           StyleRecord.class,
  174           SupBookRecord.class,
  175           TabIdRecord.class,
  176           TableRecord.class,
  177           TableStylesRecord.class,
  178           TextObjectRecord.class,
  179           TopMarginRecord.class,
  180           UncalcedRecord.class,
  181           UseSelFSRecord.class,
  182           VCenterRecord.class,
  183           VerticalPageBreakRecord.class,
  184           WindowOneRecord.class,
  185           WindowProtectRecord.class,
  186           WindowTwoRecord.class,
  187           WriteAccessRecord.class,
  188           WriteProtectRecord.class,
  189           WSBoolRecord.class,
  190   
  191           // chart records
  192           BeginRecord.class,
  193           ChartFRTInfoRecord.class,
  194           ChartStartBlockRecord.class,
  195           ChartEndBlockRecord.class,
  196   // TODO ChartFormatRecord.class,
  197           ChartStartObjectRecord.class,
  198           ChartEndObjectRecord.class,
  199           CatLabRecord.class,
  200           EndRecord.class,
  201           LinkedDataRecord.class,
  202           SeriesToChartGroupRecord.class,
  203   
  204           // pivot table records
  205           DataItemRecord.class,
  206           ExtendedPivotTableViewFieldsRecord.class,
  207           PageItemRecord.class,
  208           StreamIDRecord.class,
  209           ViewDefinitionRecord.class,
  210           ViewFieldsRecord.class,
  211           ViewSourceRecord.class,
  212       };
于 2016-05-17T10:47:57.913 回答
5

无法帮助说明为什么会引发异常,但我可以帮助您停止应用程序被强制关闭。

问题与ExceptionInInitializerError类相关联,该类不是由java.lang.Exception. 相反,它是从java.lang.Error超类派生的(参见ExceptionInInitializerError 声明

所以解决方案是为这种异常添加一个显式的 catch 块,例如,以下之一:

catch(ExceptionInInitializerError e) // catch exactly this error

catch(Error e) // catch all Java errors (not exceptions!)

catch(Throwable t) // catch all Java errors and exceptions

请注意,必须将第一个和第二个 catch 块添加到现有的 catch 中,而第三个可以替换它们,因为它们是ThrowableJava类的超类。ExceptionError

于 2016-05-12T12:49:39.337 回答
2

对我来说,这是由proguard引起的。它删除/重命名了通过反射加载的记录类。

该规则有助于:

-keep class org.apache.poi.hssf.record.** { *; }
于 2020-04-19T11:59:49.557 回答
0

任务实例必须在 UI 线程上创建。

您应该在主应用程序线程中创建任务实例。它将解决您的问题。初始化事物的最佳方法是在您的项目中创建一个应用程序类并在该应用程序类中初始化您的任务。Application 类具有全局范围,可以维护应用程序的状态。

于 2016-05-18T04:50:16.437 回答