I made a very simple Java program, using notepad and compiling by CMD .
The problem is that even the files being in the same folder, the class that has the main()
method does not compile.
The following is the code below:
Main class
public class Main {
public static void main(String[] args) {
Nada nada = new Nada();
nada.showVars();
nada.setName("maisnada");
nada.setN(16);
System.out.println();
nada.showVars();
}
}
Class Nothing
public class Nada {
private String nome;
private int numeroQualquer;
public Nada() {
this.nome = "nada";
this.numeroQualquer = 3;
}
public void setName(String nome) {
this.nome = nome;
}
public void setN(int n) {
this.numeroQualquer = n;
}
public void showVars() {
System.out.println(nome);
System.out.println(numeroQualquer);
}
}
When I try to compile Main.java, it gives the following error in CMD :
Main.java:3 error: cannot find symbol
Nada nada = new Nada();
^
symbol: class Nada
location: class Main
Main.java:3 error: cannot find symbol
Nada nada = new Nada();
^
symbol: class Nada
location: class Main
2 errors
Since the two files, Main.java and Nada.java, are in the same folder, and Nada.java compiled normally.
EDIT:
I was able to solve the problem, it was the environment variable
CLASSPATH , it was as %JAVA_HOME%\lib
instead of .;%JAVA_HOME%\lib
.
The command I used to compile was this:
javac Main.java
Thanks to all who responded.