Results 1 to 11 of 11
  1. #1
    bwilson0117's Avatar
    bwilson0117 is offline Java Beginner
    Join Date
    Jul 2011
    Location
    San Antonio, TX
    Posts
    33
    Rep Power
    0

    Default Need Help With Code Error Exception in thread "main" java.lang.NullPointerException

    import java.io.ObjectOutputStream;
    Last edited by bwilson0117; 07-23-2011 at 02:59 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,812
    Rep Power
    25

    Default

    Look at line 38 and see what variable could be null. Then trace back thru your code to see why that variable does not have a valid value.

  3. #3
    bwilson0117's Avatar
    bwilson0117 is offline Java Beginner
    Join Date
    Jul 2011
    Location
    San Antonio, TX
    Posts
    33
    Rep Power
    0

    Default

    This is line 38 ( output.format( "%d %s %s %.2f\n",) in the class, but I am not understanding what is wrong with that line.
    The blue lines are where I am seeing my errors.
    Last edited by bwilson0117; 07-20-2011 at 06:12 AM.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    There is only one variable on that line: output. So output must be null. Why is it null? That is what you have to find out. Hint: by default reference type variables are null if not initialised.

  5. #5
    bwilson0117's Avatar
    bwilson0117 is offline Java Beginner
    Join Date
    Jul 2011
    Location
    San Antonio, TX
    Posts
    33
    Rep Power
    0

    Default

    So pretty much I just need to initialize output? Is that what your saying?

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    It's upto you. Try it and see what happens.

  7. #7
    bwilson0117's Avatar
    bwilson0117 is offline Java Beginner
    Join Date
    Jul 2011
    Location
    San Antonio, TX
    Posts
    33
    Rep Power
    0

    Default

    I changed
    Formatter output = null;
    AccountRecord accounts[] = new AccountRecord[ 4 ];
    To
    Formatter output = new Formatter();
    AccountRecord accounts[] = new AccountRecord[ 4 ];

    Now it compiles, is that what you were telling me to do?

  8. #8
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Once again it is upto you what you do. I can't tell you to do anything. But if the changes you made produce the correct results then why bother asking me.

  9. #9
    bwilson0117's Avatar
    bwilson0117 is offline Java Beginner
    Join Date
    Jul 2011
    Location
    San Antonio, TX
    Posts
    33
    Rep Power
    0

    Default

    Ok. Appreciate you guys helping me.

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,812
    Rep Power
    25

    Default

    Now it compiles,
    It compiled before with the null value, but it didn't execute without an error.
    Does it execute ok now? Or at least not give you the NullPointerException.

  11. #11
    bwilson0117's Avatar
    bwilson0117 is offline Java Beginner
    Join Date
    Jul 2011
    Location
    San Antonio, TX
    Posts
    33
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    It compiled before with the null value, but it didn't execute without an error.
    Does it execute ok now? Or at least not give you the NullPointerException.
    Yes it actually execute ok now. Thanks for all your help, I greatly appreciate it.

Similar Threads

  1. Replies: 2
    Last Post: 09-22-2010, 11:31 PM
  2. Replies: 5
    Last Post: 06-22-2010, 04:51 PM
  3. Replies: 6
    Last Post: 07-16-2009, 04:30 PM
  4. Replies: 1
    Last Post: 07-16-2009, 11:35 AM
  5. Replies: 1
    Last Post: 07-16-2007, 07:32 AM

Posting Permissions

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