Free Support Forum - aspose.com

Getting Error java.lang.NumberFormatException: For input string: " "

Hi,

Is there any way to find the Space in the cell.it throws Error java.lang.NumberFormatException: For input empty string: " ".

How can i avoid this. here is my code.

for (int n1=0;n1<num;n1++)
{ if (cells.checkCell(n1,0).getValue()== null )
{ Cell cell=cells.getCell(n1,0);
Style style = cells.getCell(n1,0).getStyle();
style.setColor(Color.TEAL);
cell.setStyle(style);
}else if ( cells.checkCell(n1,0).getValue()== " " )
{
Cell cell=cells.getCell(n1,0);
Style style = cells.getCell(n1,0).getStyle();
style.setColor(Color.TEAL);
cell.setStyle(style);

}else
{
double intCounter = Double.parseDouble(cells.checkCell(n1,0).getValue().toString());
if(intCounter!=Count)
{
Cell cell=cells.getCell(n1,0);
Style style = cells.getCell(n1,0).getStyle();
style.setColor(Color.RED);
cell.setStyle(style);
}
}

Thanks in Advance.

Hi,

I think, then you should add another explicit check to verify if your input string is empty. If it is not empty, only then you should try converting it to numbers.

You can check if it is empty by using cell.getStringValue()=="" condition.

Hi,

Firstly, to check whether two strings are equal in Java, please use equals() method instead of "==” operator.

Secondly, Cells.checkCell() may return null when the specific cell was not instantiated. Your code should be like following:

for (int n1=0;n1<num;n1++)
{
Cell cell = cells.getCell(n1, 0);
//Or use cells.checkCell() like: Cell cell = cells.checkCell(n1,0); if(cell != null){...}
if (cell.getValue()== null )
{...}else if(“”.equals(cell.getValue()))
{...}else...