4
I made a very simple Java program, using the notepad and compiling by CMD.
The problem is that even though the files are in the same folder, the class that has the method main()
does not compile.
Follow 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();
}
}
Classe Nada
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, the following error occurs 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
The two files, Main.java and Nada.java, are in the same folder, and Nada.java compiled normally.
EDIT:
I managed to solve the problem, it was the environment variable
CLASSPATH, she was like %JAVA_HOME%\lib
instead of .;%JAVA_HOME%\lib
.
The command I used to compile was this:
javac Main.java
Thank you to all who responded.
What command did you use to compile? You checked the current folder -
.
- is in theCLASSPATH
? For example:javac -cp . Main.java
– mgibsonbr
I used javac Main.java
– Rafael
Edith your question and add the command you are using to compile.
– Jéf Bueno
You are using packages?
– Math
No, but I already solved, it was the same CLASSPATH. It was worth the help.
– Rafael