Results 1 to 3 of 3

Thread: NullPointException error

  1. #1
    Join Date
    Jul 2006
    Posts
    249
    Rep Power
    0

    Default NullPointException error

    Code:
        private int search_array_2 (String ac_num) {
            int line= 0;
            String answer = null;
            for (int a = 0; a <1000; a++){
                if ((acc_info [2][a]).equals(ac_num)) {
                    line = a;
                    a = a + 1000;
                }
                else {
                    line = -1;
                }
            }
            return line;
        }
    when i run this method it keeps giving me this error (pointing to the if statement)

    Code:
    Exception in thread "main" java.lang.NullPointerException

    any thoughts??

    thanks for the help in advance
    "And what's the real lesson? Don't leave things in the fridge"

  2. #2
    Join Date
    Jun 2003
    Posts
    453
    Rep Power
    0

    Default

    maybe if you explain what it is that you want to do we can better assist.
    a = a + 1000;
    that seems flawed from my viewpoint but i am sure you have a reason for doing that. Try also to include the entire error message or as much as possible. If you dont want to post your code for whatever reason, PM me and I will see if I can help.
    We Is Friends!
    Me And You Is Friends!
    You Smile, I Smile ....
    You Hurt, I Hurt ..
    You Cry, I Cry ..
    You Jump Off A Bridge ..
    I Gonna Miss Your E-Mails !

  3. #3
    Join Date
    Dec 2002
    Posts
    500
    Rep Power
    0

    Default

    Code:
    if ((acc_info [2][a]).equals(ac_num)) {
    either
    a. acc_info is null or
    b. acc_info [2] is null or
    c. acc_info [2][a] is null or
    d. ac_num is null

    acc_info is null if there was no call to acc_info = new String[][],
    Code:
        private int search_array_2 (String ac_num) {
            int line= 0;
            String answer = null;
            for (int a = 0; a <1000 ; a++){
                if ( acc_info[2][a] != null && acc_info[2][a].equals(ac_num) ) {
                    line = a; // return a;
                    a = a + 1000;
                }
                else {
                    line = -1;
                }
            }
            return line; // return -1; // would have been straight forward
        }
    i'm thinking ...
    acc_info [2][a] is null... most likely reason is you allocated a buffer for x (1000) amount of records but it has not been completely filled.

    N.B.
    there does seem something non-OO about a double indexed array of strings.

    ASIDE
    Code:
    a = a+ 1000; // i guess you want a < 1000 == false
    just say
    Code:
    break; // this will jump out of the inner most loop
    Last edited by icymint3; Dec 22, 2006 at 07:56 PM.
    Cultured in Aggression and Koding like a Warrior!!
    “Common sense is instinct. Enough of it is genius.” - George Bernard Shaw.
    "The significant problems we face cannot be solved by the same level of thinking that created them." - Albert Einstein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •