Fetting a null pointer exception at line 3: Object[][] parameters = readFile(fil
ID: 3887608 • Letter: F
Question
Fetting a null pointer exception at line 3: Object[][] parameters = readFile(filename,2);
Ponly when I try to use @Parameterized.Parameters
need modified operation.
Current operation is as follows:
@Parameterized.Parameters
public static int[][] data() {
Object[][] parameters = readFile(filename,2);
for (int i = 0; i <= parameters.length-1; i++) {
result = countA(parameters[i][0].toString());
expectedResult = Integer.valueOf(parameters[i][1].toString());
array[i][0] = result;
array[i][1] = expectedResult;
}
return array;
}
Explanation / Answer
Solution:
nullPointerExceptions occurs only when we are pointing to a null reference which means to a location which is not pointing to the memory(null), that is why we get nulllPointerExceptions.
in Object[][] parameters = readFile(filename,2);
Here object reference is explicitly to be set to parameters on readFile, but the readFile is containing null as a value, that is the main reason behind this error nullPointerException.
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.