tags:

views:

613

answers:

3
+2  Q: 

Cannot Find Symbol

+6  A: 

You have a Math class, and you're attempting to use the abs() method.

The question is: Is it your intention to provide this function or are you trying to use the one in java.lang.Math?

For the first, you have to make sure you're declaring that function.

For the second you have to make sure you're using the correct parameters types; see Math.

Does your Math class have the abs method?

It seems like your Math class is shadowing the Math class that comes in the core of the language.

Your Math class is loaded and the abs method could not be found (hence the "Cannot find symbol" message)

OscarRyz
It was my intention to use the Math class built into java.lang.
Patrick Cassell
+3  A: 

In your compiler output, you have:

./Math.java:13: cannot find symbol

It looks like you're trying to write your own Math class, and it's shadowing java.lang.Math, which is builtin.

Do you have to have a class of your own called Math? If not, then just delete Math.java and try to compile this again. If you do need Math.java, then try renaming it to something else (like, say, MyMath.java with public class MyMath defined inside).

tgamblin
I did not mean to create my own Math class. When I used the fully qualified class name the error disappeared.
Patrick Cassell
Nice. Dunno where it's getting Math.java then, but good luck w/your project!
tgamblin
+4  A: 

If you want your program to use Java's Math.abs (instead of an abs() method in the Math class you wrote), you can say:

if(z - y == x && java.lang.Math.abs(y - z) == z)

...which isn't very pretty. In general, try not to name your classes the same as the ones in java.lang (or java.anything, really).

kristina
It was my intention to use the Math class built into java.lang. I believe I accidentally called a class that I did not make instead of calling java.lang.Math. When I made the change the errors disappeared. Thank you.
Patrick Cassell