2
I am doing a study on Java and would like to learn without using those Ides full of resources that do everything. After several attempts to learn how to use packages by creating them manually, one class is failing to see others outside the package. Follow a totally generic example:
The folder structure is as follows:
-pacotes
Teste.java(classe com main)
--objeto
Texto.java
And the file codes are as follows::
-> Java test.
package pacotes;
import pacotes.objeto.*;
public class Teste{
public static void main(String[] args) {
Texto t = new Texto();
}
}
-> Java text.
package pacotes.objeto;
public class Texto{
public Texto(){
System.out.println("Construiu um objeto");
}
}
When compiling the Text.java file everything happens normally, but when compiling Test.java says the package 'packages.object' does not exist, which is wrong?
Are you using any IDE (Netbeans, Eclipse, etc) or are using text editor only (e.g., notepad)?
– NilsonUehara
My intention is to avoid netbeans or eclipse as I want to learn manually
– leandroungari
That’s what I thought... by the way you are trying to compile only the Test class. See my answer below showing how to compile the project.
– NilsonUehara
I deleted the previous comment because I saw something I didn’t have in the accepted answer. Besides you said that your example is completely generic, so the fact that the Text class does not have a public constructor is probably not a problem in your real example, however I will fix it because the way it is does not work.
– Math