0

Does anyone know why I am getting an NullPointerException:Null error for this method?

public int[] checkISBN()

{
String letter;
int[] isbnCheck = new int[9];
for (int i = 0; i < 9; i++)
{
letter = isbn.substring(i,i+1); 
isbnCheck[i] = Integer.parseInt(letter);
}
return isbnCheck;

This is the specs for this class:

check ISBN for correctness. The ISBN number (for books published before January 1 2007, and we will use this type of ISBN) is a series of 9 digits and one last digit or letter. The last entry is computed as follows: if (abcdefghi) are the first nine digit, compute a*1 + b*2 + c*3 + d*4 + e*5 + f*6 + g*7 + h*8 + i * 9 then compute the remainder of the division of the above sum by 11 (use the % operator). The result of this calculation is then the last digit of the ISBN. If the result of the calculation is 10, the last entry of the ISBN is X. Therefore, your method will check the ISBN for correctness and return true or false according to its findings.

3
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by jwenting
0

Your post does not indicate any reason for getting a NullPointerException. My guess is that the isbn String is null but that's just a guess. Could you print out the stack trace and see what line it is occurring at? That would help you locate the exact cause.

0

that's the only possible reason I see.
A major flaw is also the use of what seems to be a global variable, isbn should really be a parameter to the method and be checked for length and nullness as well.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.