Troubleshooting Error: Cannot Find Symbol in Java Code

In summary, I'm guessing that when you compile your code, the compiler isn't able to find the library code.
  • #1
whatisreality
290
1
My program says it doesn't recognise the symbol signum(double) or sqrt(double)! I have definitely done the whole import java.lang.Math; thing. And signum and sqrt aren't symbols anyway. Is that too vague? I can post the actual code.

It's only my second week learning java, so it's supposed to be pretty straightforward stuff.
 
Technology news on Phys.org
  • #2
whatisreality said:
My program says it doesn't recognise the symbol signum(double) or sqrt(double)! I have definitely done the whole import java.lang.Math; thing. And signum and sqrt aren't symbols anyway. Is that too vague? I can post the actual code.

It's only my second week learning java, so it's supposed to be pretty straightforward stuff.
Yes, the source code and imports would help.
 
  • Like
Likes whatisreality
  • #3
whatisreality said:
My program says it doesn't recognise the symbol signum(double) or sqrt(double)! I have definitely done the whole import java.lang.Math; thing. And signum and sqrt aren't symbols anyway. Is that too vague? I can post the actual code.
I'm guessing that when you compile your code, the compiler isn't able to find the library code. The term "symbol" is computerese for the name of a variable, function, what-have-you, not a symbol such as ##\Sigma## or ##\int##. Even if your source code has a line where you import some library, if your installation isn't set up correctly, the compiler won't be able to find the code for functions you're importing.
 
  • Like
Likes whatisreality
  • #4
Are you trying to use the actual symbol ##\sqrt ()## in your source code instead of Math.sqrt()?

Java supports unicode but it doesn't support using the ##\sqrt()## symbol or +- signum as valid operators in expressions. It instead requires you to type Math.sqrt() or use + and - for a number's sign.
 
Last edited:
  • Like
Likes whatisreality
  • #5
jedishrfu said:
Are you trying to use the actual symbol ##\sqrt ()## in your source code instead of Math.sqrt()?

Java supports unicode but it doesn't support using the ##\sqrt()## symbol or +- signum as valid operators in expressions. It instead requires you to type Math.sqrt() or use + and - for a number's sign.
You are a hero! I forgot to put Math.sqrt! I was just using sqrt. And now my code works!

Thanks for all the replies, really appreciate it :)
 

What does "Error: cannot find symbol" mean?

"Error: cannot find symbol" means that the compiler cannot locate a specific symbol (such as a variable, method, or class) that is being referenced in the code.

What can cause this error?

This error can be caused by a variety of issues, such as misspelling the symbol name, not declaring the symbol in the correct scope, or not importing the necessary libraries.

How do I fix this error?

To fix this error, you should first double check the spelling and declaration of the symbol. If that is not the issue, then make sure the necessary libraries are imported. If all else fails, try restarting the compiler or IDE.

Can this error occur in any programming language?

Yes, this error can occur in any programming language that uses a compiler. However, the specific wording of the error message may vary depending on the language.

Is there a way to prevent this error?

While it is impossible to completely prevent this error, there are ways to minimize the chances of encountering it. These include using descriptive and consistent naming conventions, properly declaring and scoping symbols, and carefully checking for errors before running the code.

Similar threads

  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
2
Views
12K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
6K
  • Programming and Computer Science
Replies
15
Views
2K
  • Programming and Computer Science
Replies
3
Views
2K
Replies
1
Views
946
Replies
18
Views
2K
  • Programming and Computer Science
Replies
5
Views
1K
Back
Top