Results 1 to 7 of 7

Thread: double

  1. #1
    isme is offline Member
    Join Date
    Apr 2010
    Posts
    18
    Rep Power
    0

    Default double

    im getting null pointer exception for the code below

    double volume = volumeToCompare.getTime();
    any idea how to avoid the null pointer exception?

  2. #2
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Make sure volumeToCompare exists before you call one of its methods.

    You haven't presented enough code to allow us to be more helpful than that.

    -Gary-

  3. #3
    isme is offline Member
    Join Date
    Apr 2010
    Posts
    18
    Rep Power
    0

    Default

    yes, already declared. here's how it really goes:

    volumeToCompare = time.getCurrentDateTime();
    double volume = volumeToCompare.getTime();

  4. #4
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    And what is time? What exactly does your null pointer error message say? We need more code to put this in context.

    -Gary-

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    Yes, what does getTime() return?
    Is it, by any chance, a Double and not a double?

  6. #6
    1060406004020 is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Default

    what's volumeToCompare?

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    volumeToCompare = time.getCurrentDateTime();
    double volume = volumeToCompare.getTime();
    Did anyone ever tell you about using meaningful variable names? On the face of it, assigning the return value of getCurrentDateTime() to a variable volumeToCompare is absurd, and setting volume to the return value of getTime() is equally bad.

    db

Similar Threads

  1. double a * double b = weird output
    By GPB in forum New To Java
    Replies: 3
    Last Post: 03-26-2010, 10:40 AM
  2. Check if double is double
    By marshalthrone in forum New To Java
    Replies: 8
    Last Post: 09-30-2009, 02:51 PM
  3. Replies: 5
    Last Post: 03-21-2009, 09:32 PM
  4. Double
    By Xystus777 in forum New To Java
    Replies: 2
    Last Post: 01-21-2009, 10:39 AM
  5. Double.valueOf() vs Double.parseDouble()
    By greenbean in forum New To Java
    Replies: 10
    Last Post: 01-12-2009, 08:39 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
  •