| | |
NullPointerException:
![]() |
Does anyone know why I am getting an NullPointerException:Null error for this method?
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.
Java Syntax (Toggle Plain Text)
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.
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.
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.
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
![]() |
Similar Threads
- Word Association Game (Posting Games)
- GUI Window - Exit Button? (Java)
- Compiling And Running (Java)
- Thinking OOP!: From BASIC to JAVA (Java)
- Need some help with a Java lab... (Java)
Other Threads in the Java Forum
- Previous Thread: please tell me, why we named java as Java 2
- Next Thread: Convert the following swing application into applet as soon as possible
| Thread Tools | Search this Thread |
6 @param actuate android api applet application arc array arrays automation balls binary bluetooth bold business byte c++ chat class client code codesnippet collections compare component coordinates database defaultmethod detection doctype dragging ebook eclipse educational error file fractal froglogic game givemetehcodez graphics gui guitesting helpwithhomework hql html ide ideas image ingres input integer internet intersect invokingapacheantprogrammatically j2me java javaexcel javaprojects jni jpanel jtextarea julia linux list map method methods mobile mysql netbeans newbie nextline parameter php pong problem program programming project recursion recursive scanner sell server set sms sort sql string sun swing swt terminal threads tree web websites windows






