我收到以下错误,
2019-01-24 12:11:27,579 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.apache.jmeter.threads.JMeterVariables; import org.apache.poi.ss.userm . . . '' : Typed variable declaration : Class: Workbook not found in namespace.
2019-01-24 12:11:27,579 WARN o.a.j.e.BeanShellPostProcessor: Problem in BeanShell script: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.apache.jmeter.threads.JMeterVariables; import org.apache.poi.ss.userm . . . '' : Typed variable declaration : Class: Workbook not found in namespace
我正在尝试执行以下代码
import org.apache.jmeter.threads.JMeterVariables;
import org.apache.poi.ss.usermodel.Cell;
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.xssf.usermodel.XSSFWorkbook;
import java.io.File;
import java.io.FileInputStream;
log.info("before");
FileInputStream excelFile = new FileInputStream(new File("File Path"));
log.info("excelFile");
Workbook wb = new XSSFWorkbook(excelFile);
excelFile.close();
log.info("before3");
Sheet s = wb.getSheetAt(0);
//Sheet s = wb.getSheet("Bulk Upload");
int lines = FileUtils.readLines(new File("File Path")).size(); // get lines count
//vars.put("lines", String.valueOf(lines)); // store the count into "lines" variable
int i;
for(i=0; i<=lines;i++)
{
log.info("during");
Row row = s.getRow(i);
Cell a1 = row.getCell(0);
String a1Value = a1.getStringCellValue();
Cell a2 = row.getCell(1);
String a2Value = a2.getStringCellValue();
Cell a3 = row.getCell(2);
String a3Value = a3.getStringCellValue();
Cell a4 = row.getCell(3);
String a4Value = a4.getStringCellValue();
}
log.info("after");
请让我知道为什么会出现此错误以及在哪里进行更正
答案 0 :(得分:0)
之所以发生这种情况,是因为Apache POI JAR文件未在您的类路径上正确设置。您需要将其添加到您的类路径中。
或者,如果您确定确实在类路径中包括了JAR文件,请确保您没有遇到菱形依赖问题,并且同时使用了两个不同的版本。根据{{3}}的类似问题(尽管显然不是重复的),Apache POI在类路径上的多个版本上不能很好地工作。