Writing an android app that uses excel files and ran into a bump in the road. It loads files without pictures just fine, but the moment I try to load an excel file that has pictures embedded in it, I get this errror:
01-16 14:50:37.927 28377-28377/com.dcheeseman.csvflashcards W/System.err: org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:62)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:426)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:431)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:155)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:221)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at com.dcheeseman.csvflashcards.SpreadsheetReader.getPicturesXlsx(SpreadsheetReader.java:119)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at com.dcheeseman.csvflashcards.FlashCardActivity.onActivityResult(FlashCardActivity.java:215)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at android.app.Activity.dispatchActivityResult(Activity.java:6549)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at android.app.ActivityThread.deliverResults(ActivityThread.java:4084)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at android.app.ActivityThread.handleSendResult(ActivityThread.java:4131)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at android.app.ActivityThread.access$1400(ActivityThread.java:179)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1511)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at android.os.Looper.loop(Looper.java:145)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5972)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at java.lang.reflect.Method.invoke(Native Method)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at java.lang.reflect.Method.invoke(Method.java:372)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: Caused by: java.lang.reflect.InvocationTargetException
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at java.lang.reflect.Constructor.newInstance(Native Method)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:60)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: ... 18 more
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards 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
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing$Factory.parse(Unknown Source)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: at org.apache.poi.xssf.usermodel.XSSFDrawing.<init>(XSSFDrawing.java:84)
01-16 14:50:37.947 28377-28377/com.dcheeseman.csvflashcards W/System.err: ... 21 more
My concern is the class cast exception at the end. It's a pain getting POI to compile in an android environment and I had to use version 3.9 of POI. I'm wondering if this is a bug that just hasn't been fixed yet.
Here's the very short code segment related to it:
String Fpath = data.getDataString();
InputStream is2 = getContentResolver().openInputStream(Uri.parse(Fpath));
List<XSSFPictureData> lst = SpreadsheetReader.getPicturesXlsx(is2);
public static List<XSSFPictureData> getPicturesXlsx(InputStream is)
{
List<XSSFPictureData> lst = null;
XSSFWorkbook wb = null;
try {
wb = new XSSFWorkbook(is);
lst = wb.getAllPictures();
} catch (IOException e) {
e.printStackTrace();
}
return lst;
}
There error trips on the 'wb = new XSSFWorkbook(is);' line, which has worked just fine with excel files that have no images. Also of note, at this point in my code, no other application or code segment is accessing the file. Thanks in advance for any help.