Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Error Message on Java Compiler

Options
  • 22-03-2004 3:24pm
    #1
    Registered Users Posts: 488 ✭✭


    Exception in thread "main" java.lang.NullPointerException
    at Directory.main(Directory.java:26)

    Anyone know what the problem is....


Comments

  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    The problem is in line 26 of Directory.java

    beyond that you don't have enough information to supply a proper answer.


  • Registered Users Posts: 1,636 ✭✭✭henbane


    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/NullPointerException.html probly doesn't help and awful lot but is as good a place as any to start.

    Twould be a good idea to post a little code when you want answers to this kind of thing. Or possibly just go to java.sun.com first


  • Registered Users Posts: 488 ✭✭lad12


    On line 26 i use an array to read in information...

    Array.get();

    and in the method get i read in 2 strings and an int from the keyboard...can you read in 3 parts of information into 1 component of the array...


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Doesn't seem to make a whole pile of sense.
    Post up your whole code, so we have proper context.


  • Registered Users Posts: 1,636 ✭✭✭henbane


    Originally posted by lad12
    Array.get();
    Looks like i might be reaching a value larger than the size of the array.
    and in the method get i read in 2 strings and an int from the keyboard...can you read in 3 parts of information into 1 component of the array...

    If you have created a class with the relevant attributes and the array is of that type, it shouldn't be a problem.


  • Advertisement
  • Registered Users Posts: 491 ✭✭Silent Bob


    Originally posted by lad12
    Exception in thread "main" java.lang.NullPointerException
    at Directory.main(Directory.java:26)

    Anyone know what the problem is....
    It means you've tried to reference something that quite simply does not exist. The usual culprit is iterating over the end of an array, or trying to call a method on a reference which has been set to null.


  • Closed Accounts Posts: 1,502 ✭✭✭MrPinK


    I'm guessing you created an array of objects, but didn't initialise them. It's a little different than creating an array of primative types.
    int[] Array = new int[10];
    // that works fine alright
    
    myObject[] Array = new myObject[];
    // not done yet. You've only created the refs to the objects....
    for(int i = 0; i < 10; i++)
       Array[i] = new myObject();
    // now you have an created all the objects
    

    This wouldn't happen to be a Joe Morris assignment, would it? :)


Advertisement