Results 1 to 8 of 8
Thread: Odd error
- 12-05-2010, 10:34 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 68
- Rep Power
- 0
Odd error
Can anyone tell me why I would get this 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
"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.
-
blu is an array, so how can it have a value method?
- 12-05-2010, 10:45 PM #3
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
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-
-
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.
- 12-05-2010, 11:12 PM #5
Member
- Join Date
- Oct 2010
- Posts
- 68
- Rep Power
- 0
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!
-
- 12-05-2010, 11:17 PM #7
Member
- Join Date
- Oct 2010
- Posts
- 68
- Rep Power
- 0
-
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
-
java out of memory error-heap space error
By elsanthosh in forum NetBeansReplies: 4Last Post: 06-15-2010, 09:31 AM -
> Operator cannot be applied error and return incompatible types error
By corney_16 in forum New To JavaReplies: 1Last Post: 03-10-2010, 01:53 PM -
Thread: Error 500--Internal Server Error java.lang.NullPointerException
By jackdear44 in forum New To JavaReplies: 1Last Post: 12-05-2009, 07:28 AM -
java.lang.Error: Error opening DSound for capture
By NARs in forum NetworkingReplies: 1Last Post: 10-26-2009, 04:38 PM -
Diference Between compiler error Garbage collection and Runtime Error?
By makpandian in forum New To JavaReplies: 3Last Post: 01-23-2009, 08:53 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks