Hello I am trying to update an existing Excel file In my app while using Java.
The file is located in the internal storage of the device and I'm wondering if I need to change the excel file type in order to have this working correctly. I changed from an HSSFWorkbook to an XSSFWorkbook because the HSSFWorkbook said there was an issue with the file header.
This is my code:
exStorageDirectory = Environment.getExternalStorageDirectory().toString();
Log.e("DIRECTORY", exStorageDirectory);
try {
InputStream file = new FileInputStream(new File(exStorageDirectory + "/ZCK Orders/ZLM_Order_MASTER.xlsx"));
XSSFWorkbook workbook = new XSSFWorkbook(file);
XSSFSheet sheet = workbook.getSheetAt(0);
dateRow = sheet.getRow(4);
dateCell = dateRow.getCell(7);
dateCell.setCellValue(currentDate);
//Quesitos
quesitoRow = sheet.getRow(8);
quesitoCell = quesitoRow.getCell(7);
quesitoCell.setCellValue(quesitoOrder);
//Guava
guavaRow = sheet.getRow(9);
guavaCell = guavaRow.getCell(7);
guavaCell.setCellValue(guavaOrder);
//Guava Cheese
guavaCheeseRow = sheet.getRow(10);
guavaCheeseCell = guavaCheeseRow.getCell(7);
guavaCheeseCell.setCellValue(guavaCheeseOrder);
//Cuban Bread
cubanBreadRow = sheet.getRow(11);
cubanBreadCell = cubanBreadRow.getCell(7);
cubanBreadCell.setCellValue(cubanBreadOrder);
//Media Noche
mediaNocheRow = sheet.getRow(12);
mediaNocheCell = mediaNocheRow.getCell(7);
mediaNocheCell.setCellValue(mediaNocheOrder);
//Fries
friesRow = sheet.getRow(13);
friesCell = friesRow.getCell(7);
friesCell.setCellValue(friesOrder);
//Tostones
tostonesRow = sheet.getRow(14);
tostonesCell = tostonesRow.getCell(7);
tostonesCell.setCellValue(tostonesOrder);
//Maduros
madurosRow = sheet.getRow(15);
madurosCell = madurosRow.getCell(7);
madurosCell.setCellValue(madurosOrder);
//Palomilla
palomillaRow = sheet.getRow(16);
palomillaCell = palomillaRow.getCell(7);
palomillaCell.setCellValue(palomillaOrder);
//Croq
croquetasRow = sheet.getRow(17);
croquetasCell = croquetasRow.getCell(7);
croquetasCell.setCellValue(croquetasOrder);
//Chicken Soup
chickenSoupRow = sheet.getRow(18);
chickenSoupCell = chickenSoupRow.getCell(7);
chickenSoupCell.setCellValue(chickenSoupOrder);
//Veggie Meat
veggieMeatRow = sheet.getRow(19);
veggieMeatCell = veggieMeatRow.getCell(7);
veggieMeatCell.setCellValue(veggieMeatOrder);
//Turkey Patty
turkeyRow = sheet.getRow(20);
turkeyCell = turkeyRow.getCell(7);
turkeyCell.setCellValue(turkeyOrder);
//Bacon
baconRow = sheet.getRow(21);
baconCell = baconRow.getCell(7);
baconCell.setCellValue(baconOrder);
//Mahi Mahi
mahiRow = sheet.getRow(22);
mahiCell = mahiRow.getCell(7);
mahiCell.setCellValue(mahiOrder);
//Beef Emp
beefEmpRow = sheet.getRow(23);
beefEmpCell = beefEmpRow.getCell(7);
beefEmpCell.setCellValue(beefEmpOrder);
//Chicken Emp
chickenEmpRow = sheet.getRow(24);
chickenEmpCell = chickenEmpRow.getCell(7);
chickenEmpCell.setCellValue(chickenEmpOrder);
//Ham Cheese
hcEmpRow = sheet.getRow(25);
hcEmpCell = hcEmpRow.getCell(7);
hcEmpCell.setCellValue(hcEmpOrder);
//Mini Beef Emp
miniBeefEmpRow = sheet.getRow(26);
miniBeefEmpCell = miniBeefEmpRow.getCell(7);
miniBeefEmpCell.setCellValue(miniBeefEmpOrder);
//Mini Chicken Emp
miniChickenEmpRow = sheet.getRow(27);
miniChickenEmpCell = miniChickenEmpRow.getCell(7);
miniChickenEmpCell.setCellValue(miniChickenEmpOrder);
//Prov
provRow = sheet.getRow(28);
provCell = provRow.getCell(7);
provCell.setCellValue(provOrder);
//Swiss
swissRow = sheet.getRow(29);
swissCell = swissRow.getCell(7);
swissCell.setCellValue(swissOrder);
//Cilantro
cilantroRow = sheet.getRow(30);
cilantroCell = cilantroRow.getCell(7);
cilantroCell.setCellValue(cilantroOrder);
//Pickles
picklesRow = sheet.getRow(31);
picklesCell = picklesRow.getCell(7);
picklesCell.setCellValue(picklesOrder);
//Chop Onions
chopOnionsRow = sheet.getRow(32);
chopOnionsCell = chopOnionsRow.getCell(7);
chopOnionsCell.setCellValue(chopOnionsOrder);
//Eggs
eggsRow = sheet.getRow(33);
eggsCell = eggsRow.getCell(7);
eggsCell.setCellValue(eggsOrder);
//Butter
butterRow = sheet.getRow(34);
butterCell = butterRow.getCell(7);
butterCell.setCellValue(butterOrder);
//Lettuce
lettuceRow = sheet.getRow(35);
lettuceCell = lettuceRow.getCell(7);
lettuceCell.setCellValue(lettuceOrder);
//Pork
porkRow = sheet.getRow(36);
porkCell = porkRow.getCell(7);
porkCell.setCellValue(porkOrder);
//Chicken
chickenRow = sheet.getRow(37);
chickenCell = chickenRow.getCell(7);
chickenCell.setCellValue(chickenOrder);
//Vaca
vacaRow = sheet.getRow(38);
vacaCell = vacaRow.getCell(7);
vacaCell.setCellValue(vacaOrder);
//Congri
congriRow = sheet.getRow(39);
congriCell = congriRow.getCell(7);
congriCell.setCellValue(congriOrder);
//Black B
blackBeansRow = sheet.getRow(40);
blackBeansCell = blackBeansRow.getCell(7);
blackBeansCell.setCellValue(blackBeansOrder);
//Red B
redBeansRow = sheet.getRow(41);
redBeansCell = redBeansRow.getCell(7);
redBeansCell.setCellValue(redBeansOrder);
//Ropa Vieja
ropaRow = sheet.getRow(42);
ropaCell = ropaRow.getCell(7);
ropaCell.setCellValue(ropaOrder);
//Red Peppers
peppersRow = sheet.getRow(43);
peppersCell = peppersRow.getCell(7);
peppersCell.setCellValue(peppersOrder);
//Garlic
garlicRow = sheet.getRow(44);
garlicCell = garlicRow.getCell(7);
garlicCell.setCellValue(garlicOrder);
//B Ham
breakHamRow = sheet.getRow(45);
breakHamCell = breakHamRow.getCell(7);
breakHamCell.setCellValue(breakHamOrder);
//Cuban Ham
cubHamRow = sheet.getRow(46);
cubHamCell = cubHamRow.getCell(7);
cubHamCell.setCellValue(cubHamOrder);
//Picadillo
picadilloRow = sheet.getRow(47);
picadilloCell = picadilloRow.getCell(7);
picadilloCell.setCellValue(picadilloOrder);;
//Mojo
mojitoRow = sheet.getRow(48);
mojitoCell = mojitoRow.getCell(7);
mojitoCell.setCellValue(mojitoOrder);
//Veggies
veggiesRow = sheet.getRow(49);
veggiesCell = veggiesRow.getCell(7);
veggiesCell.setCellValue(veggiesOrder);
//Potatoes
potatoesRow = sheet.getRow(50);
potatoesCell = potatoesRow.getCell(7);
potatoesCell.setCellValue(potatoesOrder);
//Onions
roastOnionsRow = sheet.getRow(51);
roastOnionsCell = roastOnionsRow.getCell(7);
roastOnionsCell.setCellValue(roastOnionsOrder);
//Flan
flanRow = sheet.getRow(52);
flanCell = flanRow.getCell(7);
flanCell.setCellValue(flanOrder);
//Cubaioli
cubaioliRow = sheet.getRow(53);
cubaioliCell = cubaioliRow.getCell(7);
cubaioliCell.setCellValue(cubaioliOrder);
//Mayoketchup
mayoKRow = sheet.getRow(54);
mayoKCell = mayoKRow.getCell(7);
mayoKCell.setCellValue(mayoKOrder);
//Zaza Verde
hotSauceRow = sheet.getRow(55);
hotSauceCell = hotSauceRow.getCell(7);
hotSauceCell.setCellValue(hotSauceOrder);
//OJ
ojRow = sheet.getRow(56);
ojCell = ojRow.getCell(7);
ojCell.setCellValue(ojOrder);
//Milk
milkRow = sheet.getRow(57);
milkCell = milkRow.getCell(7);
milkCell.setCellValue(milkOrder);
//Fat Free
fatFreeRow = sheet.getRow(58);
fatFreeCell = fatFreeRow.getCell(7);
fatFreeCell.setCellValue(fatFreeOrder);
//Almond
almondRow = sheet.getRow(59);
almondCell = almondRow.getCell(7);
almondCell.setCellValue(almondOrder);
//Adobo
adoboRow = sheet.getRow(60);
adoboCell = adoboRow.getCell(7);
adoboCell.setCellValue(adoboOrder);
//Almibar
almibarRow = sheet.getRow(61);
almibarCell = almibarRow.getCell(7);
almibarCell.setCellValue(almibarOrder);
//Jupina
jupinaRow = sheet.getRow(62);
jupinaCell = jupinaRow.getCell(7);
jupinaCell.setCellValue(jupinaOrder);
//Cola
colaRow = sheet.getRow(63);
colaCell = colaRow.getCell(7);
colaCell.setCellValue(colaOrder);
//Malta
maltaRow = sheet.getRow(64);
maltaCell = maltaRow.getCell(7);
maltaCell.setCellValue(maltaOrder);
file.close();
FileOutputStream fos = new FileOutputStream(new File(
exStorageDirectory + "/ZCKOrders/ZLM_ZCK_Order_"
+ tomorrow +".xls"));
workbook.write(fos);
fos.close();
} catch (FileNotFoundException e){
Toast.makeText(this, e.toString(), Toast.LENGTH_SHORT).show();
} catch (IOException e ){
Toast.makeText(this, e.toString(), Toast.LENGTH_SHORT).show();
}
}
This is the error I get in my Log:
2020-07-16 02:16:12.646 22351-22351/com.customapps.zazatrainingapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.customapps.zazatrainingapp, PID: 22351
java.lang.BootstrapMethodError: Exception from call site #238 bootstrap method
at org.apache.poi.openxml4j.opc.PackagePartCollection.<init>(PackagePartCollection.java:47)
at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:241)
at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:732)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:310)
at org.apache.poi.ooxml.util.PackageHelper.open(PackageHelper.java:47)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:309)
at com.example.jorge.zazaii.ZNCD.Management.ZLM.Orders.ZCKOrderFinal.updateExcelFile(ZCKOrderFinal.java:649)
at com.example.jorge.zazaii.ZNCD.Management.ZLM.Orders.ZCKOrderFinal.access$100(ZCKOrderFinal.java:40)
at com.example.jorge.zazaii.ZNCD.Management.ZLM.Orders.ZCKOrderFinal$1.onClick(ZCKOrderFinal.java:255)
at android.view.View.performClick(View.java:6610)
at android.view.View.performClickInternal(View.java:6583)
at android.view.View.access$3100(View.java:780)
at android.view.View$PerformClick.run(View.java:26076)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6702)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)
Caused by: java.lang.ClassCastException: Bootstrap method returned null
at org.apache.poi.openxml4j.opc.PackagePartCollection.<init>(PackagePartCollection.java:47)
at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:241)
at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:732)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:310)
at org.apache.poi.ooxml.util.PackageHelper.open(PackageHelper.java:47)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:309)
at com.example.jorge.zazaii.ZNCD.Management.ZLM.Orders.ZCKOrderFinal.updateExcelFile(ZCKOrderFinal.java:649)
at com.example.jorge.zazaii.ZNCD.Management.ZLM.Orders.ZCKOrderFinal.access$100(ZCKOrderFinal.java:40)
at com.example.jorge.zazaii.ZNCD.Management.ZLM.Orders.ZCKOrderFinal$1.onClick(ZCKOrderFinal.java:255)
at android.view.View.performClick(View.java:6610)
at android.view.View.performClickInternal(View.java:6583)
at android.view.View.access$3100(View.java:780)
at android.view.View$PerformClick.run(View.java:26076)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6702)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)
I have been searching BootstrapMethodError but apparently there many different types. I know that it has found the file because perviously the log gave me the error of not finding the file. If anyone can guide me I'd truly appreciate it, Thanks!