File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes double cannot be dereferenced Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "double cannot be dereferenced" Watch "double cannot be dereferenced" New topic
Author

double cannot be dereferenced

Accela Moon
Greenhorn

Joined: Apr 11, 2004
Posts: 20
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

Joined: Mar 13, 2004
Posts: 1272
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.


Mike Gershman
SCJP 1.4, SCWCD in process
Warren Dew
blacksmith
Ranch Hand

Joined: Mar 04, 2004
Posts: 1332
    
    2
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

Joined: Apr 11, 2004
Posts: 20
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

Joined: Oct 08, 2001
Posts: 2937
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

Joined: Apr 11, 2004
Posts: 20
Oh, my bad. I've fixed it, thanks a million!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: double cannot be dereferenced