andruhon/AndroidReadXLSX

java.lang.ClassCastException: org.apache.xmlbeans.impl.values.XmlComplexContentImpl cannot be cast to org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing

Closed this issue · 9 comments

When reading excel with images, I get this error.

03-31 16:57:39.119 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:62)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:426)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:431)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:155)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:221)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at pro.kondratev.xlsxpoiexample.MainActivity.onReadClick(MainActivity.java:42)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at android.view.View$1.onClick(View.java:3818)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at android.view.View.performClick(View.java:4438)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at android.view.View$PerformClick.run(View.java:18422)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at android.os.Looper.loop(Looper.java:136)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5001)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at dalvik.system.NativeStart.main(Native Method)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: Caused by: java.lang.reflect.InvocationTargetException
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at java.lang.reflect.Constructor.constructNative(Native Method)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:60)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: ... 19 more
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: Caused by: java.lang.ClassCastException: org.apache.xmlbeans.impl.values.XmlComplexContentImpl cannot be cast to org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing$Factory.parse(Unknown Source)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: at org.apache.poi.xssf.usermodel.XSSFDrawing.(XSSFDrawing.java:84)
03-31 16:57:39.129 23479-23479/pro.kondratev.xlsxpoiexample W/System.err: ... 22 more

Hi it is known not to work with some embedded objects. You can try to copy appropriate class from full schemas file https://github.com/andruhon/android5xlsx/blob/master/poi-ooxml-schemas-3.12-20150511-a.jar

(andruhon: please note this is an issue with android 5 version, not with this one)
Hi Andruhon,

Got the same error,

What do you mean by copy appropriate class from full schemas file, could you detail please?

Here is the log
Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance(Native Method) at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:60) at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:456)  at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:461)  at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:162)  at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:271)  at com.arris.bolo.export.ExcelExporter.loadWorkbook(ExcelExporter.java:111)  at com.arris.bolo.export.ExcelExporter.init(ExcelExporter.java:68)  at com.arris.bolo.export.ExcelExporter.process(ExcelExporter.java:155)  at com.arris.bolo.strategy.ExcelExportStrategy.execute(ExcelExportStrategy.java:35)  at com.arris.bolo.interactor.ExportSurvey.lambda$buildUseCaseObservable$0$ExportSurvey(ExportSurvey.java:32)  at com.arris.bolo.interactor.ExportSurvey$$Lambda$0.apply(Unknown Source)  at io.reactivex.internal.operators.observable.ObservableFlatMap$MergeObserver.onNext(ObservableFlatMap.java:121)  at io.reactivex.internal.operators.observable.ObservableMap$MapObserver.onNext(ObservableMap.java:63)  at io.reactivex.internal.operators.observable.ObservableCreate$CreateEmitter.onNext(ObservableCreate.java:67)  at com.arris.bolo.repository.DummyDataRepository.lambda$getSurveyEntity$0$DummyDataRepository(DummyDataRepository.java:73)  at com.arris.bolo.repository.DummyDataRepository$$Lambda$2.subscribe(Unknown Source)  at io.reactivex.internal.operators.observable.ObservableCreate.subscribeActual(ObservableCreate.java:40)  at io.reactivex.Observable.subscribe(Observable.java:10514)  at io.reactivex.internal.operators.observable.ObservableMap.subscribeActual(ObservableMap.java:32)  at io.reactivex.Observable.subscribe(Observable.java:10514)  at io.reactivex.internal.operators.observable.ObservableFlatMap.subscribeActual(ObservableFlatMap.java:55)  at io.reactivex.Observable.subscribe(Observable.java:10514)  at io.reactivex.internal.operators.observable.ObservableSubscribeOn$1.run(ObservableSubscribeOn.java:39)  at io.reactivex.internal.schedulers.ExecutorScheduler$ExecutorWorker$BooleanRunnable.run(ExecutorScheduler.java:256)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)  at java.lang.Thread.run(Thread.java:818)  Caused by: java.lang.ClassCastException: org.apache.xmlbeans.impl.values.XmlComplexContentImpl cannot be cast to schemasMicrosoftComOfficeOffice.CTShapeLayout at schemasMicrosoftComOfficeOffice.CTShapeLayout$Factory.parse(Unknown Source) at org.apache.poi.xssf.usermodel.XSSFVMLDrawing.read(XSSFVMLDrawing.java:117) at org.apache.poi.xssf.usermodel.XSSFVMLDrawing.<init>(XSSFVMLDrawing.java:102) at java.lang.reflect.Constructor.newInstance(Native Method)  at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:60)  at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:456)  at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:461)  at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:162)  at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:271)

@fabrice999 sorry for misleading you. I've deleted my previous comments to not mislead someone else. https://github.com/andruhon/android5xlsx/blob/master/poi-ooxml-schemas-3.12-20150511-a.jar is already aavax hacked.

  1. First check if it works on desktop with the same code and the same (but full) version of POI, if it doesn't - it doesn't;
  2. If it does work, try to check if the class, it cannot cast to, exists in reduced/shrunk jar;
  3. If it doesn't exist in shrunk jar but does in full - copy it over from full jar to shrunk one and try again.

Hi Andruhon,

The org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing is part of the poi-ooxml-schemas-3.12-20150511-a.jar, at runtime this class is found otherwise I will get a ClassNotFoundException.

The error is more related to this cast:
Caused by: java.lang.ClassCastException: org.apache.xmlbeans.impl.values.XmlComplexContentImpl cannot be cast to schemasMicrosoftComOfficeOffice.CTShapeLayout at schemasMicrosoftComOfficeOffice.CTShapeLayout$Factory.parse(Unknown Source)

But I have no idea how to solve it, do you know how to fix this?

@fabrice999 do you have the same one on desktop with normal POI?

This is working with Android 7 but not with Android 5 and 6 with my app. but as my app is multi modules (1 android lib + java lib), perhaps they are problems of classloading especially when you are doing multidexing.

If I use a sample app with your libs with android 5,6,7 this is working fine.

Do you know how to fix this issue of classloading?

@fabrice999 sorry, I don't. Do you need to support Android 4? If you don't need you'd better try this one https://github.com/andruhon/android5xlsx

Hi Andruhon,
No, I don't have to support Android 4.

I was using these libs you generated from this project https://github.com/andruhon/android5xlsx.

Did you compile the libs with Java8?

@fabrice999 I didn't compile the library, it was downloaded from official POI website and hacked to make it work on Android. I think it was compiled using Java 8.

The fact that you already using android 5 version changes everything - it already has a full library and no need to copy anything to and fro. If it doesn't work - it is likely to be a POI defect. Next time please create an issue in appropriate repository, I was trying to help you considering that you using this android 4 version.