Error Message:
Exception in thread "main" java.lang.IllegalStateException: Cannot get a STRING value from a NUMERIC cell at org.apache.poi.xssf.usermodel.XSSFCell.typeMismatch(XSSFCell.java:1050) at org.apache.poi.xssf.usermodel.XSSFCell.getRichStringCellValue(XSSFCell.java:404) at org.apache.poi.xssf.usermodel.XSSFCell.getRichStringCellValue(XSSFCell.java:70) at com.jawasoft.testDemo.ExcelUtil.readExcel(ExcelUtil.java:81) at com.jawasoft.testDemo.ExcelUtil.readExcelToObj(ExcelUtil.java:46) at com.jawasoft.testDemo.ExcelUtil.main(ExcelUtil.java:29)
Reason for error: When reading the cell string, there is data of type number, so it needs to be converted into pure String type, so that no error will be reported.
Error code:
returnStr = cell.getRichStringCellValue().getString();
or the following code
// Get cell data String cellValue = cell.getStringCellValue();
Solution: Set the cell type to String before reading the excel cell data conversion
code show as below:
//set cell type cell.setCellType(CellType.STRING); returnStr = cell.getRichStringCellValue().getString();
Read More:
- [Solved] Android mediaplayer.prepare() Error: Caused by: java.lang.IllegalStateException
- [Solved] Android Error: java.lang.IllegalStateException: Not allowed to start service Intent
- How to Solve Error: Android java.lang.IllegalStateException: Could not execute method of the activity
- [Solved] MindSpore Error: For ‘CellList’, each cell should be subclass of Cell
- [Solved] Wwagger error: java.lang.NumberFormatException: For input string: ““
- JSON parse error: Can not deserialize instance of java.lang.String out of START_OBJECT token
- [Solved] IDEA JSP File out.println Error: Cannot resolve method ‘println(java.lang.String)’
- Kafka error: ERROR There was an error in one of the threads during logs loading: java.lang.NumberFormatException: For input string: “derby” (kafka.log.LogManager)
- Java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()Ljava/lang/Integer; error resolution
- Hive ERROR Failed with exception java.io.IOException:java.lang.IllegalArgumentException
- [Solved] Response Export error on submit request on future invoke, java.lang.OutOfMemoryError: Java heap space
- [Solved] java.lang.reflect.InaccessibleObjectException: Unable to make protected java.net.http.HttpRequest()…
- Idea Error: java: java.lang.OutOfMemoryError: GC overhead limit exceeded
- [Solved] Hadoop error java.lang.nosuchmethoderror
- [HBase Error]“java.lang.OutOfMemoryError: Requested array size exceeds VM limit”
- [Solved] jhat Analyzes dump File Error: java.lang.OutOfMemoryError
- [Solved] Caused by: java.lang.ClassNotFoundException: org.apache.flink.api.common.typeinfo.TypeInformation
- Tomcat startup error: java.lang.NoClassDefFoundError
- [Solved] Flume Error: java.lang.NoClassDefFoundError: org/apache/hadoop/conf/Configuration