我遇到了这个 TestNG DataProvider 方法的问题。谁能告诉我为什么会发生这个错误并帮助我修复这个类?我无法插入数组。
我得到的错误是模糊的:
Caused by: java.lang.NullPointerException
at tr.test.TestScript.createData(TestScript.java:55)
这是我的代码:
@SuppressWarnings("resource")
@DataProvider(name = "addresses")
public Object[][] createData() {
Object[][] objs = new Object[100][];
CSVReader reader = null;
try {
reader = new CSVReader( new FileReader("input.csv"), ',' );
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Object[] nextLine;
int row = 0;
try {
while ( ( nextLine = reader.readNext() ) != null ) {
System.out.println( "Adding test case " + (row+1) + ": " + nextLine[0] + ", " + nextLine[1] + ", " + nextLine[2] );
objs[row][0] = nextLine[0]; //this is line #55
objs[row][1] = nextLine[1];
objs[row][2] = nextLine[2];
row++;
}
} catch (IOException e) {
e.printStackTrace();
}
if ( objs == null ) {
System.out.println("Error: Input file empty.");
System.exit(0);
}
return objs;
}