Results 1 to 5 of 5
  1. #1
    Kris is offline Member
    Join Date
    Sep 2009
    Posts
    2
    Rep Power
    0

    Question NullPointerException problem

    Hello

    I'm in IB computer science and i'm working on a program for my dossier, but every time i try and invoke a specific method i keep recieving a nullpointerexception message in the terminal. Can anyone help me? I also posted the code below:

    public static void addProduct()
    {
    for(i = 0; i < array0.length; i++)
    {
    if(array0[i].contains(tfText1.getText()))
    {
    if(arrayA[x] == null)
    {
    arrayA[x] = array0[i];
    arrayB[x] = array1[i];
    arrayC[x] = array2[i];
    arrayD[x] = array3[i];
    arrayE[x] = array4[i];
    arrayF[x] = array5[i];
    }
    else{
    x++;
    }
    }
    else if(array1[i].contains(tfText2.getText()))
    {
    if(arrayA[x] == null)
    {
    arrayA[x] = array0[i];
    arrayB[x] = array1[i];
    arrayC[x] = array2[i];
    arrayD[x] = array3[i];
    arrayE[x] = array4[i];
    arrayF[x] = array5[i];
    }
    else{
    x++;
    }
    }
    else if(array2[i].contains(tfText3.getText()))
    {
    if(arrayA[x] == null)
    {
    arrayA[x] = array0[i];
    arrayB[x] = array1[i];
    arrayC[x] = array2[i];
    arrayD[x] = array3[i];
    arrayE[x] = array4[i];
    arrayF[x] = array5[i];
    }
    else{
    x++;
    }
    }
    else if(array3[i].contains(tfText4.getText()))
    {
    if(arrayA[x] == null)
    {
    arrayA[x] = array0[i];
    arrayB[x] = array1[i];
    arrayC[x] = array2[i];
    arrayD[x] = array3[i];
    arrayE[x] = array4[i];
    arrayF[x] = array5[i];
    }
    else{
    x++;
    }
    }
    else{
    System.out.println("There is no such item in the inventory");
    }
    }
    }

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    The stack trace tells you the exact line number where the problem is.
    On that line number, you are calling dot (.) on a variable that has not been initialized.

  3. #3
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    805
    Rep Power
    6

    Default

    u just put printStackTrace() and find out the line number.
    Still if ur are not able to trace,then print erraor message and complete code with code tag.
    Ramya:cool:

  4. #4
    Kris is offline Member
    Join Date
    Sep 2009
    Posts
    2
    Rep Power
    0

    Unhappy

    I did a printStackTrace() and foud the line number where the problem was but the variables had already been declared as fields and made in my constructor. I tried to rename the array that i was accessing from but it didn't help. Does anyone have any ideas? The source code is below:

    public void addToSale()
    {
    try{
    int i = dave.length;
    for(x = 0; x < i; x++)
    {
    for(z = 0; z < i; z++)
    if(dave[x].contains(tfText3.getText()))
    {
    album1[z] = album0[x];
    artist1[z] = artist0[x];
    genre1[z] = genre0[x];
    isbn1[z] = dave[x];
    price1[z] = price0[x];
    qty1[z] = qty0[x];
    }
    else
    {
    System.out.println( "Item not found" );
    }
    }
    }
    catch(NullPointerException e)
    {
    e.printStackTrace();
    }
    }

  5. #5
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Which line was reported for the exception and post the code where you initialized the concerned variables.

Similar Threads

  1. NullPointerException
    By tommyyyy in forum New To Java
    Replies: 9
    Last Post: 03-26-2009, 10:51 PM
  2. NullPointerException I NEED HELP
    By mayhewj7 in forum New To Java
    Replies: 2
    Last Post: 02-13-2009, 08:03 AM
  3. NullPointerException
    By Aika in forum New To Java
    Replies: 8
    Last Post: 11-18-2008, 11:34 PM
  4. nullPointerException problem
    By conandor in forum Networking
    Replies: 1
    Last Post: 08-14-2007, 01:22 PM
  5. NullPointerException problem
    By warship in forum AWT / Swing
    Replies: 5
    Last Post: 08-10-2007, 04:43 PM

Posting Permissions

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