I have two classes Owning and OwningAccessor. The files are in the same directory.
public class Owning {
String _name = "";
public void printBanner()
{
}
public void printOwning(double amount)
{
printBanner();
//print details
System.out.println("name:" + _name);
System.out.println("amount:" + amount);
}
}
public class OwningAccessor {
public void access()
{
Owning o = new Owning();
o.printOwning(500);
}
}
When I tried to compile OwningAccessor
with javac -cp . OwningAccessor.java
, I got compilation error.
symbol : class Owning
location: class smcho.OwningAccessor
Owning o = new Owning();
^
OwningAccessor.java:6: cannot find symbol
symbol : class Owning
location: class smcho.OwningAccessor
Owning o = new Owning();
^
What's wrong with this? The code compiles fine under eclipse IDE.
javac is not recognized is an error occurs while we compile the Java application. It is because the JVM is unable to find the javac.exe file. The javac.exe file is located in the bin folder of the JDK. The reason behind to occur the error is that the PATH is not added to the System's environment variable.
Output. In the above program, "Cannot find symbol" error will occur because “sum” is not declared. In order to solve the error, we need to define “int sum = n1+n2” before using the variable sum.
Misspelled method name Misspelling an existing method, or any valid identifier, causes a cannot find symbol error. Java identifiers are case-sensitive, so any variation of an existing variable, method, class, interface, or package name will result in this error, as demonstrated in Fig. 3.
It means that javac.exe executable file, which exists in bin directory of JDK installation folder is not added to PATH environment variable. You need to add JAVA_HOME/bin folder in your machine's PATH to solve this error. You cannot compile and run Java program until your add Java into your system's PATH variable.
Make sure you compile both Owning.java and OwningAccessor.java, like so:
javac -cp . Owning.java OwningAccessor.java
Eclipse compiles all necessary files for you, which is why does work there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With