我正在使用beanshell Postprocessor写入Excel工作表但我得到了#34; Typed变量声明"错误。什么是类型化声明错误以及如何解决它?
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.jmeter.services.FileServer;
import java.io.File;
import java.io.FileInputStream;
vars.put("ActualResponseTime", String.valueOf(prev.getTime()));
String v1=vars.get("ExpectedResponseTime");
String v2=vars.get("ActualResponseTime");
FileInputStream excelFile = new FileInputStream("C://Users//a622821//Desktop//New folder (2)//apache-jmeter-3.2//Jmeter_Project//Result.xlsx");
XSSFWorkbook workbook = new XSSFWorkbook(excelFile);
XSSFSheet sheet = workbook.getSheetAt(0);
XSSFRow row = sheet.getRow(0);
Cell a1 = row.getCell(0);
a1.setCellValue(v1);
Cell a2=row.getCell(1);
a2.setCellValue(v2);
FileOutputStream out = new FileOutputStream("C://Users//a622821//Desktop//New folder (2)//apache-jmeter-3.2//Jmeter_Project//Result.xlsx"));
workbook.write(out);
out.close();
答案 0 :(得分:0)
此行中有不必要的括号:
FileOutputStream out = new FileOutputStream("C://Users//a622821//Desktop//New folder (2)//apache-jmeter-3.2//Jmeter_Project//Result.xlsx");
该陈述应仅以一个括号结尾
(这个是可选的)你有额外的正斜杠,你应该修改你的代码:
FileOutputStream out = new FileOutputStream("C:/Users/a622821/Desktop/New folder (2)/apache-jmeter-3.2/Jmeter_Project/Result.xlsx");
您可以将代码置于try block之内,以获取更易读的错误消息:
try {
//your code here
}
catch (Exception ex) {
log.error("Beahshell failure", ex);
}
这样您就可以在 jmeter.log 文件中找到stacktrace
另请注意starting from JMeter 3.1 it is recommended to use JSR223 Elements and Groovy language for scripting所以请考虑在下一个可用的机会转移到Groovy。有关详细信息,请参阅Apache Groovy - Why and How You Should Use It文章。