我在调试时得到以下错误。当我设置断点并进行调试时,会发现未找到的来源'错误。
我已点击"编辑源查找路径"在Eclipse中添加我的项目。但它不起作用。请建议
Exception in thread "main" java.lang.NullPointerException
error line String value = cell.getStringCellValue();
package ExcelPractice;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFEvaluationWorkbook;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ExcelTest {
public static void main(String[] args) throws IOException {
String value = getExcelData("sheet1",2,2);
System.out.println(" Cell Value " + value);
}
public static String getExcelData( String sheetName , int rowNum ,int cellNum) throws IOException{
FileInputStream fInput = new FileInputStream("C:\\Users\\xxxx\\Excel Data.xlsx");
XSSFWorkbook wb = new XSSFWorkbook(fInput);
XSSFSheet sheet = wb.getSheet(sheetName);
XSSFRow row = sheet.getRow(rowNum);
XSSFCell cell = row.getCell(cellNum);//breakpoint is here
String value = cell.getStringCellValue();
return value;
}
}
答案 0 :(得分:1)
对于标准Java Runtime中的类,最简单,最简单的答案始终是安装JDK,并使用它编译和运行Java应用程序。理想情况下,您的Installed JREs
首选项页面应仅列出JDK。