This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Java in General and the fly likes Java Double cannot be dereferenced Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Java Double cannot be dereferenced" Watch "Java Double cannot be dereferenced" New topic
Author

Java Double cannot be dereferenced

Megan Hart
Greenhorn

Joined: Dec 08, 2010
Posts: 6
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

Shouldn't that be


[My Blog]
All roads lead to JavaRanch
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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

Joined: Dec 08, 2010
Posts: 6
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!
 
GeeCON Prague 2014
 
subject: Java Double cannot be dereferenced