Shirish Herwade
Shirish Herwade

Reputation: 11711

android ExceptionInInitializerError Caused by Unable to determine record types while new HSSFWorkbook(inputStream)

Getting error

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) 

 

For the second line(new HSSFWorkbook from InputStream) FileInputStream fileInS = new FileInputStream(outputXlsFile); hwb = new HSSFWorkbook(fileInS);

where org.apache.poi.hssf.usermodel.HSSFWorkbook is from apachePoi library

Upvotes: 4

Views: 417

Answers (4)

user2229336
user2229336

Reputation: 289

For me this was caused by proguard. It removed/renamed record classes, which were loaded via reflection.

This rule helped:

-keep class org.apache.poi.hssf.record.** { *; }

Upvotes: 2

Muhammad Zahab
Muhammad Zahab

Reputation: 1105

The task instance must be created on the UI thread.

You should create your task instance in main application thread.It will solve your problem. The best way to initialize things is to create an Application class in your project and initialized your task in that application class. The Application class have global scope and can maintain the state of your application.

Upvotes: 0

mommcilo
mommcilo

Reputation: 946

Excel Records

In database terminology, a record holds all the information or data about one specific object that has been entered into the database. In Excel, records are normally organized in worksheet rows with each cell in the row containing one item of information or value.

Based on code of RecordFactory from

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

It looks like you get some objects(in this case Records) that are not compatible with a version of poi you have. It looks like your record is not of any type specified in RecordFactory. So you should check how on server side those files are created and code related to the Records. Or if they are created manually you should check Excel or Open Office version and see which type of Records they support and compare them with library you are using on Android devices.

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

Upvotes: 5

Carlo
Carlo

Reputation: 1579

Cant' help about why exception is thrown, but I can help you about stopping the app being force closed.

The problem is linked to the ExceptionInInitializerError class, that isn't derived by java.lang.Exception. Instead it is derived from java.lang.Error superclass (see ExceptionInInitializerError declaration)

So the solution is to add an explicit catch block for such kind of exception like, for example, one of the following:

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

Note that first and second catch blocks must be added to your existing catches, while third one can substitute them, because Throwable is superclass of both Exception and Error Java classes.

Upvotes: 5

Related Questions