It's not a secret anymore!*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 14687
    
  16

Shouldn't that be


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

Joined: Nov 24, 2005
Posts: 14687
    
  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!
 
 
subject: Java Double cannot be dereferenced
 
Similar Threads
Help w/ Data Input Error
Not being able to compile
creating a new JPanel from another JPanel "choice" button
Double compiler error - Help!
Double compiler error - Help!