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

Java Double cannot be dereferenced

 
Megan Hart
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All, I am very new to Java and I am getting a 'Double cannot be dereferenced' error when I try to compile this code.

public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if (source == exitButton)
System.exit(0);
else if (source == calculateButton)
{
double sideAValue = Double.parseDouble(sideAField.getText());
double sideBValue = Double.parseDouble(sideBField.getText());

double sideCValue = Math.hypot(sideAValue, sideBValue);
sideCValue.setText(Double.toString(sideCValue));

The above section of code is part of a larger program that calculates the hypotenuse of a right triangle when the user enters the two smaller sides.

The error comes from this line of code:
sideCValue.setText(Double.toString(sideCValue));

Could someone please help me to know how to fix this?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shouldn't that be
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the ranch Next time you want to post some code, don't forget to UseCodeTags. This will be make it easier to read.
 
Megan Hart
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it should be! Thanks for alerting me to that error. I will be sure to use code tags next time around! Thanks for the welcome!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic