# Double cannot be dereferenced

Page 1 of 1

## 6 Replies - 1169 Views - Last Post: 22 January 2013 - 04:20 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=308670&amp;s=e35ebf967298883f050e71a7017cc4a4&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 lyates93

Reputation: 0
• Posts: 8
• Joined: 22-January 13

# Double cannot be dereferenced

Posted 22 January 2013 - 10:12 AM

Having problems comparing to objects radius... says double cannot be dereferenced. I'm new to the equals method and greaterThan method so I need some help!

``` public class Circle
{

public Circle(double r)
{

}

public double getArea()
{

}

{

}

public String toString()
{

String str = "The radius is: " + getRadius() + "and the area is: " + getArea(); ;

return str;

}

public boolean equals(Circle circle1)
{

boolean status;

status=true;
else
status=false;
return status;

}

public boolean greaterThan(Circle circle1)
{

boolean status;

if(getArea().greaterThan(circle1.getArea()))
status=true;

else
status=false;

return status;

}
}

```

Here is my demo class
```public class CircleDemo
{

public static void main(String [] args)
{

Circle circle1 = new Circle(1.44);
Circle circle2 = new Circle(3.22);

System.out.println(circle1);

if(circle1.equals(circle2))
System.out.println("Both objects have the same radius and area.");
else
System.out.println("The objects have different radi and areas.");

if(circle1.greaterThan(circle2))
System.out.println("Circle 1 is greater than circle 2.");
else
System.out.println("Circle 1 is not greater than circle 2.");

}

}

```

Is This A Good Question/Topic? 0

## Replies To: Double cannot be dereferenced

### #2 blackcompe

• D.I.C Lover

Reputation: 1158
• Posts: 2,538
• Joined: 05-May 05

## Re: Double cannot be dereferenced

Posted 22 January 2013 - 10:18 AM

```this.getArea().equals(circle1.getArea())

```

In equals(), you're calling getArea() which returns a primitive type (double), but then you're trying to call a method on it, which is illegal. Use the equality operator to compare primitive types. Also, why make calls to getRadius() in your instance methods when you can use radius directly?

This post has been edited by blackcompe: 22 January 2013 - 10:19 AM

### #3 lyates93

Reputation: 0
• Posts: 8
• Joined: 22-January 13

## Re: Double cannot be dereferenced

Posted 22 January 2013 - 10:49 AM

So what am I supposed to do?

use the == signs?

I changed it to this, and I still have the same problem

```public boolean equals(Circle circle1)
{

boolean status;

status=true;
else
status=false;
return status;

}

```

### #4 blackcompe

• D.I.C Lover

Reputation: 1158
• Posts: 2,538
• Joined: 05-May 05

## Re: Double cannot be dereferenced

Posted 22 January 2013 - 11:41 AM

As stated, you can't deference (i.e. calling a method on) a primitive type (i.e. int, char, boolean, double, etc.). You are still doing so, and the compiler is telling you that can't. Primitive types can be compared to each other using relational and equality operators (i.e. > < == !=). Why don't you try that and see if it works?

This post has been edited by blackcompe: 22 January 2013 - 11:41 AM

### #5 lyates93

Reputation: 0
• Posts: 8
• Joined: 22-January 13

## Re: Double cannot be dereferenced

Posted 22 January 2013 - 03:59 PM

Now I have this... And my outputs are not correct. It says Circle 1 is greater than Circle 2. Also, when I change the circle objects to have the same radius, it says they area and radi are different. What am I doing wrong here?

```
public boolean equals(Circle circle2)
{

boolean status;

status=true;
else
status=false;
return status;

}

```

Demo code...

```
public class CircleDemo
{

public static void main(String [] args)
{

Circle circle1 = new Circle(1.44);
Circle circle2 = new Circle(1.44);

System.out.println(circle1);

if(circle1.equals(circle2))
System.out.println("Both objects have the same radius and area.");
else
System.out.println("The objects have different radi and areas.");

if(circle1.greaterThan(circle2))
System.out.println("Circle 1 is greater than circle 2.");
else
System.out.println("Circle 1 is not greater than circle 2.");

}

}

```

### #6 lyates93

Reputation: 0
• Posts: 8
• Joined: 22-January 13

## Re: Double cannot be dereferenced

Posted 22 January 2013 - 04:07 PM

I'm confused on what to call the object in the equals(....) method, and how to utilize that in the if statements?

### #7 blackcompe

• D.I.C Lover

Reputation: 1158
• Posts: 2,538
• Joined: 05-May 05

## Re: Double cannot be dereferenced

Posted 22 January 2013 - 04:20 PM

Quote

Now I have this... And my outputs are not correct. It says Circle 1 is greater than Circle 2. Also, when I change the circle objects to have the same radius, it says they area and radi are different. What am I doing wrong here?

If a circle has a single attribute, wouldn't its equality be based solely on that attribute?

```public boolean equals(Object other)
{
if(!(other instanceof Circle))
return false;