Reputation: 121
I am executing below mentioned java code with Windows system. It is working fine without any error. But i try to execute this code with Linux environment i am getting "java.lang.reflect.InvocationTargetException" error.
String status = "Initialized!";
try
{
String rootPath = "C:/FolderA.1/FolderA1.1.1/FolderA1.1.1A/"; /**Windows**/
String rootPath = "/opt/FolderA/FolderA.1/FolderA1.1.1/FolderA1.1.1A/"; /**Linux**/
String reportFileLocation = rootPath + File.separator + fileName;
FileInputStream excelFile = new FileInputStream(new File(reportFileLocation));
XSSFWorkbook workbook = new XSSFWorkbook((InputStream)excelFile);
{
XSSFSheet reportSheet = workbook.getSheet("Report");
XSSFSheet formatSheet = workbook.getSheet("Format");
if(reportSheet == null)
{
workbook.close();
throw new Exception("Sheet name \"Report\" is not available! Please add \"Report\" sheet!");
}
if(formatSheet == null)
{
workbook.close();
throw new Exception("Sheet name \"Format\" is not available! Please add \"Format\" sheet!");
}
/** Delete other sheets **/
int sheetsCount = workbook.getNumberOfSheets();
int s = 0;
for( ;s < sheetsCount; s++)
{
String sheetName = workbook.getSheetName(s);
if(sheetName.equals("Report") || sheetName.equals("Format"))
{
}
else
{
workbook.removeSheetAt(s);
sheetsCount--;
s--;
}
}
}
FileOutputStream outputStream = new FileOutputStream(reportFileLocation);
workbook.getCreationHelper().createFormulaEvaluator().evaluateAll();
workbook.write((OutputStream)outputStream);
workbook.close();
status = "OK";
}
catch(Exception err)
{
status = err.getMessage();
}
How to resolve this issue?
Upvotes: 0
Views: 432
Reputation: 121
Thanks for the response @Gagravarr.
Got an exact error message with below code and resolved.
try
{
//my logic
}
catch(Exception err)
{
status = err.getMessage();
status = status + err.getCause();
}
Upvotes: 0