Ao tentar compilar uma classe que usa outra classe do mesmo pacote dá o seguinte erro:
[color=red]
D:\Users\Andreia\Documents\NetBeansProjects\JavaApplicationTeste\novoPrograma1\Teste.java:5: cannot find symbol
symbol : class Pessoa
location: class novoPrograma1.Teste
Pessoa p = new Pessoa();
^
D:\Users\Andreia\Documents\NetBeansProjects\JavaApplicationTeste\novoPrograma1\Teste.java:5: cannot find symbol
symbol : class Pessoa
location: class novoPrograma1.Teste
Pessoa p = new Pessoa();
^
2 errors
[/color]
A classe que estou tentando compilar está assim:
package novoPrograma1;
public class Teste {
public static void main(String[] args) {
Pessoa p = new Pessoa();
p.setNome("Andréia");
System.out.println("Hello, "+p.getNome()+"!");
}
}
Para compilar uso esta classe:
public class CompilerTeste {
private static String projectPath = "";
private static String outputDir = "";
static {
try {
projectPath = new File(".").getCanonicalPath() + "\\";
outputDir = new File(".").getCanonicalPath() + "\\compiled";
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Erro ao buscar o path do projeto. Exc: "
+ e.getMessage());
}
}
public static void main(String[] args) {
String fileToCompile = java.io.File.separator + projectPath
+ "novoPrograma1\\Teste.java";
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
int result = compiler.run(null, null, null, "-d", outputDir, fileToCompile);
if (result == 0) {
System.out.println("Compilação feita com sucesso!");
} else {
System.out.println("Erro, não foi possivel compilar");
}
}
}
Alguém sabe como resolver este problema?