I am using Apache.poi to open an .xlsx file stored on a server.
One and only one of my testers is getting InvalidFormatException when running the app. If I change the code to open the .xlsx file locally, he has no problem. He is based in the US (I am in Ireland as is the server).
I have concluded that a delay in opening the file is the problem and the poi library is deciding that the .xlsx file is corrupt.
Cut out from main section of code below. Also exception log from running from command line. Using java -jar TWRPowerCalculator.jar
I have had to remove the .xlsx file from the server for now.
package twrpowercalculator;
//Apache Poi maintain a library for manipulating excel file formats
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
//Apache Poi maintain a library for manipulating excel file formats
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.util.CellReference;
/**
*
* This class is used for all interaction with the excel file.
*/
public class ExcelInterface {
//Variables
private Sheet sheet;
private Row row;
private Cell cell;
private CellValue cellValue;
private double value;
private Workbook wb = null;
private final String fileName = "TWR_power_calculator.xlsx";
InputStream is;
private FormulaEvaluator evaluator;
public ExcelInterface() {
//Constructor opens excel workbook and formula evaluator for Excel
try {
// Web link needed for link to file on remote web site.
is = new URL("http://www.centronsolutions.com/TWRCalculator/TWR_power_calculator.xlsx").openStream();
wb = WorkbookFactory.create(is); // Needed for link to file on remote web site.
evaluator = wb.getCreationHelper().createFormulaEvaluator(); // Needed for link to file on remote web site. - And needed for direct file load.
}
catch (FileNotFoundException e)
{
System.out.println("The file " + fileName + " was not found.");
}
catch (IOException | InvalidFormatException exception)
{
System.out.println(exception);
}
}
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Lau
ncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImp
l.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherIm
pl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$156(
LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoClassDefFoundError: org/apache/poi/openxml4j
/exceptions/InvalidFormatException
at twrpowercalculator.FXMLDocumentController.<init>(FXMLDocumentControll
er.java:36)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
orAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
onstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at java.lang.Class.newInstance(Class.java:442)
at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:
927)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FX
MLLoader.java:971)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:22
0)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.ja
va:744)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at twrpowercalculator.TWRPowerCalculator.start(TWRPowerCalculator.java:3
0)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163
(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(Platfor
mImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.
java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformI
mpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatch
er.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.ja
va:191)
... 1 more
Caused by: java.lang.ClassNotFoundException:
org.apache.poi.openxml4j.exceptions
.InvalidFormatException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 25 more
Exception running application twrpowercalculator.TWRPowerCalculator