NullPointerException:

Reply

Join Date: Jan 2007
Posts: 36
Reputation: cassyjack is an unknown quantity at this point 
Solved Threads: 0
cassyjack's Avatar
cassyjack cassyjack is offline Offline
Light Poster

NullPointerException:

 
0
  #1
Jan 17th, 2007
Does anyone know why I am getting an NullPointerException:Null error for this method?


  1. public int[] checkISBN()
  2.  
  3. {
  4. String letter;
  5. int[] isbnCheck = new int[9];
  6. for (int i = 0; i < 9; i++)
  7. {
  8. letter = isbn.substring(i,i+1);
  9. isbnCheck[i] = Integer.parseInt(letter);
  10. }
  11. 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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 353
Reputation: aniseed is an unknown quantity at this point 
Solved Threads: 6
aniseed's Avatar
aniseed aniseed is offline Offline
Posting Whiz

Re: NullPointerException:

 
0
  #2
Jan 17th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: NullPointerException:

 
0
  #3
Jan 19th, 2007
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC