Results 1 to 8 of 8

Thread: Odd error

  1. #1
    ladykrimson is offline Member
    Join Date
    Oct 2010
    Posts
    69
    Rep Power
    0

    Default Odd error

    Java Code:
        public double getTotal(BlurayDVD[] blu) {
            for (int i = 0; i < blu.length; i++) {
    [COLOR="Red"][B]            totalValue += blu.value();[/B][/COLOR]
            }
            return totalValue;
        } // end method getTotal
    Can anyone tell me why I would get this error:

    "operator + cannot be applied to double,value"

    on the line that I have made bold and red?

    It works just fine in a previous program, but for some reason, it gives me this error now.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

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

    Default

    You probably mean [I]blu.value() and that will only work if the value() method of the BlurayDVD class returns a double. Also, I don't see where totalValue is declared and initialized -- that could be trouble for you too.

    -Gary-

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Yeah, you're right, he/she probably means blu[&#105;].value(). He/She needs to give a lot more information for this question to be answerable.

  5. #5
    ladykrimson is offline Member
    Join Date
    Oct 2010
    Posts
    69
    Rep Power
    0

    Default

    blu is an item from an ArrayList created from a subclass called BlurayDVD(); therefore it should have the . I did declare totalValue as a double.

    I figured it out. There was no method called "value". It was actually called "titleValue."

    Thanks for your suggestions!

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by ladykrimson View Post
    blu is an item from an ArrayList created from a subclass called BlurayDVD(); therefore it should have the . I did declare totalValue as a double.

    I figured it out. There was no method called "value". It was actually called "titleValue."

    Thanks for your suggestions!
    That's a mighty funky ArrayList as it has a length property!?

    In the future please post real code, please post actual error messages. sigh..

  7. #7
    ladykrimson is offline Member
    Join Date
    Oct 2010
    Posts
    69
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    Yeah, you're right, he/she probably means blu[i].value(). He/She needs to give a lot more information for this question to be answerable.
    :confused:

    From one extreme to the other... :D

    I wasn't certain how much of the code to include, because I didn't want anyone to go blind reading it. :p

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by ladykrimson View Post
    :confused:

    From one extreme to the other... :D

    I wasn't certain how much of the code to include, because I didn't want anyone to go blind reading it. :p
    It is an art, deciding how much to include, but the worst thing you can do is post misleading code. The code above shows blu as an array (arrays have length properties, length does not), and then tries to call a method value on the array itself which won't even compile much less run. And then you say it's not an array but an array list? So you can see how that would serve only to confuse us and make your question unanswerable.

Similar Threads

  1. java out of memory error-heap space error
    By elsanthosh in forum NetBeans
    Replies: 4
    Last Post: 06-15-2010, 09:31 AM
  2. Replies: 1
    Last Post: 03-10-2010, 01:53 PM
  3. Replies: 1
    Last Post: 12-05-2009, 07:28 AM
  4. Replies: 1
    Last Post: 10-26-2009, 04:38 PM
  5. Replies: 3
    Last Post: 01-23-2009, 08:53 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
  •