Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

double cannot be dereferenced

 
Accela Moon
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, can someone briefly explain what does this error mean? And how to solve it? Thanks.


Error:
[ edited to break long lines -ds ]
[ April 18, 2004: Message edited by: Dirk Schreckmann ]
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this.price is a double, a numeric primitive, not an object.
primitives don't have methods.
if this.price were a Double, this.price.toString() would work.
 
Warren Dew
blacksmith
Ranch Hand
Posts: 1332
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're getting the error because the primitive types - including 'double' - are not objects; they cannot have members, and in particular, don't have a toString() member method. Thus, you can't say price.toString().
Try Double.toString(price).
 
Accela Moon
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can use such a method, its listed in the double class in java specs from java webbie, I've imported java.lang.Double..
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can use such a method, its listed in the double class in java specs from java webbie, I've imported java.lang.Double
In Java there is double, and there is Double. The former one is a primitive type that has no methods, and the latter is a wrapper class that extends Number and Object, and subsequently has the corresponding methods. In your code, you can use either one, -- but understand the difference.
 
Accela Moon
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, my bad. I've fixed it, thanks a million!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic