从其他类

时间:2016-01-15 12:53:41

标签: java

我正在尝试从getrownum()方法访问main,但会引发NullPointerException

主要课程:

public class MainDriveScenario {

    public static void main(String args[]) throws Exception {
        ExcelUtils.setExcelFile(Constant.Path_TestData + Constant.File_TestCaseExecSheet, Constant.Sheet1_TestCaseExecSheet);

        int rownum = ExcelUtils.getrownum(Constant.Sheet1_TestCaseExecSheet);

        for (int i = 1; i < rownum + 1; i++) {
            String exec = ExcelUtils.getCellData(i, 2);
            System.out.println(exec);
            String testcaseID = ExcelUtils.getCellData(i, 0);
            System.out.println(testcaseID);

        }
    }

}

ExcelUtil类:

 public class ExcelUtils {

    public static void setExcelFile(String Path,String SheetName) throws Exception {

            try {

                // Open the Excel file

            FileInputStream ExcelFile = new FileInputStream(Path);

            // Access the required test data sheet

            ExcelWBook = new XSSFWorkbook(ExcelFile);

            ExcelWSheet = ExcelWBook.getSheet(SheetName);

            } catch (Exception e){

                throw (e);

            }

    }

public static int getrownum(String Sheetname) {
            int rownum = ExcelWSheet.getLastRowNum();
            return rownum;
        }
    }

0 个答案:

没有答案