Reading data from Excel in selenium getting "Error occurred during initialization of boot layer":java.lang.module.ResolutionException:

huangapple 未分类评论54阅读模式
英文:

Reading data from Excel in selenium getting "Error occurred during initialization of boot layer":java.lang.module.ResolutionException:

问题

  1. Code:
  2. package Selenium;
  3. import java.io.FileInputStream;
  4. import java.io.FileNotFoundException;
  5. import java.io.IOException;
  6. import java.util.ArrayList;
  7. import java.util.Iterator;
  8. import org.apache.poi.xssf.usermodel.XSSFSheet;
  9. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  10. import org.apache.poi.ss.usermodel.Cell;
  11. import org.apache.poi.ss.usermodel.CellType;
  12. import org.apache.poi.ss.usermodel.Row;
  13. import org.apache.poi.ss.util.NumberToTextConverter;
  14. public class excelReader {
  15. // 通过扫描整个第一行来识别测试用例列
  16. // 一旦识别出列,然后扫描整个测试用例列以识别购买测试用例行
  17. // 在获取购买测试用例行之后,提取该行的所有数据并输入测试中
  18. public static ArrayList<String> getData(String testcaseName) throws IOException {
  19. // fileInputStream 参数
  20. ArrayList<String> a = new ArrayList<String>();
  21. FileInputStream fis = new FileInputStream("C://Users//Sivaranjani Gopal//Desktop//siva.xlsx");
  22. XSSFWorkbook workbook = new XSSFWorkbook(fis);
  23. int sheets = workbook.getNumberOfSheets();
  24. for (int i = 0; i < sheets; i++) {
  25. if (workbook.getSheetName(i).equalsIgnoreCase("testdata")) {
  26. XSSFSheet sheet = workbook.getSheetAt(i);
  27. // 通过扫描整个第一行来识别测试用例列
  28. Iterator<Row> rows = sheet.iterator();
  29. Row firstrow = rows.next();
  30. Iterator<Cell> ce = firstrow.cellIterator(); // 行是单元格的集合
  31. int k = 0;
  32. int column = 0;
  33. while (ce.hasNext()) {
  34. Cell value = ce.next();
  35. if (value.getStringCellValue().equalsIgnoreCase("TestCases")) {
  36. column = k;
  37. }
  38. k++;
  39. }
  40. System.out.println(column);
  41. // 一旦识别出列,然后扫描整个测试用例列以识别购买测试用例行
  42. while (rows.hasNext()) {
  43. Row r = rows.next();
  44. if (r.getCell(column).getStringCellValue().equalsIgnoreCase(testcaseName)) {
  45. // 在获取购买测试用例行之后,提取该行的所有数据并输入测试中
  46. Iterator<Cell> cv = r.cellIterator();
  47. while (cv.hasNext()) {
  48. Cell c = cv.next();
  49. if (c.getCellTypeEnum() == CellType.STRING) {
  50. a.add(c.getStringCellValue());
  51. } else {
  52. a.add(NumberToTextConverter.toText(c.getNumericCellValue()));
  53. }
  54. }
  55. }
  56. }
  57. }
  58. }
  59. return a;
  60. }
  61. public static void main(String[] args) throws IOException {
  62. // TODO Auto-generated method stub
  63. getData("siva");
  64. }
  65. Could someone help on the error?
  66. I am getting the below exception when I run the code:
  67. > Error occurred during initialization of boot layer
  68. > java.lang.module.ResolutionException: Modules jaxb.impl and jaxb.core export package com.sun.xml.bind.v2.model.annotation to module poi
  69. Need help on the above exception.
英文:

Code :

  1. package Selenium;
  2. import java.io.FileInputStream;
  3. import java.io.FileNotFoundException;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6. import java.util.Iterator;
  7. import org.apache.poi.xssf.usermodel.XSSFSheet;
  8. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  9. import org.apache.poi.ss.usermodel.Cell;
  10. import org.apache.poi.ss.usermodel.CellType;
  11. import org.apache.poi.ss.usermodel.Row;
  12. import org.apache.poi.ss.util.NumberToTextConverter;
  13. public class excelReader {
  14. //Identify Testcases column by scanning the entire 1st row
  15. //once column is identified then scan entire testcase column to identify purchase testcase row
  16. //after you grab purchase testcase row = pull all the data of that row and feed into test
  17. public static ArrayList&lt;String&gt; getData(String testcaseName) throws IOException
  18. {
  19. // fileInputStream argument
  20. ArrayList&lt;String&gt; a = new ArrayList&lt;String&gt;();
  21. FileInputStream fis = new FileInputStream(&quot;C://Users//Sivaranjani Gopal//Desktop//siva.xlsx&quot;);
  22. XSSFWorkbook workbook=new XSSFWorkbook(fis);
  23. int sheets = workbook.getNumberOfSheets();
  24. for (int i = 0; i &lt; sheets; i++)
  25. {
  26. if (workbook.getSheetName(i).equalsIgnoreCase(&quot;testdata&quot;))
  27. {
  28. XSSFSheet sheet = workbook.getSheetAt(i);
  29. // Identify Testcases column by scanning the entire 1st row
  30. Iterator&lt;Row&gt; rows = sheet.iterator();
  31. Row firstrow = rows.next();
  32. Iterator&lt;Cell&gt; ce = firstrow.cellIterator();//row is collection of cells
  33. int k = 0;
  34. int column = 0;
  35. while (ce.hasNext())
  36. {
  37. Cell value = ce.next();
  38. if (value.getStringCellValue().equalsIgnoreCase(&quot;TestCases&quot;))
  39. {
  40. column = k;
  41. }
  42. k++;
  43. }
  44. System.out.println(column);
  45. // once column is identified then scan entire testcase column to identify purchase testcase row
  46. while (rows.hasNext())
  47. {
  48. Row r = rows.next();
  49. if (r.getCell(column).getStringCellValue().equalsIgnoreCase(testcaseName))
  50. {
  51. // after you grab purchase testcase row = pull all the data of that row and feed into test
  52. Iterator&lt;Cell&gt; cv = r.cellIterator();
  53. while (cv.hasNext())
  54. {
  55. Cell c = cv.next();
  56. if (c.getCellTypeEnum() == CellType.STRING)
  57. {
  58. a.add(c.getStringCellValue());
  59. }
  60. else
  61. {
  62. a.add(NumberToTextConverter.toText(c.getNumericCellValue()));
  63. }
  64. }
  65. }
  66. }
  67. }
  68. }
  69. return a;
  70. }
  71. public static void main(String[] args) throws IOException
  72. {
  73. // TODO Auto-generated method stub
  74. getData(&quot;siva&quot;);
  75. }

Could some one help on the error?

I am getting the below exception when I run the code:

> Error occurred during initialization of boot layer
> java.lang.module.ResolutionException: Modules jaxb.impl and jaxb.core export package com.sun.xml.bind.v2.model.annotation to module poi

Need help on the above exception.

huangapple
  • 本文由 发表于 2020年4月8日 16:46:20
  • 转载请务必保留本文链接:https://java.coder-hub.com/61096707.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定