0
I’m trying to make a import of a package in java, but I’m very doubtful and I can’t do it.
Here’s the thing, I got a package at the following address:
C:\projetos_de_programacao_do_atom\classes\carro
While I leave the. java files in the address:
C:\projetos_de_programacao_do_atom\projetos.em.java
But when I compile it by the console appears the following result:
import classes.carro.* ; ^ CarroTeste.java:12: error: cannot access Carro Carro carro = new Carro ( ) ; ^ bad source file: .\Carro.java file does not contain class Carro Please remove or make sure it appears in the correct subdirectory of the sourcepath. 2 errors
The codes are below so you can take a look:
Java carousel.:
import java.util.* ;
import classes.carro.* ;
public class CarroTeste
{
public static void main ( String [ ] args )
{
Scanner ler = new Scanner ( System.in ) ;
Carro carro = new Carro ( ) ;
}
}
The file I will import will be the Carro.class
and your java file will be:
package classes.carro ;
public class Carro
{
String placa ;
String modelo ;
String velocidadeMaxima ;
}
How are you compiling? Which command?
– user28595
i am the command : javac -d .. (filename ). java . It builds this other normal file, only when I call it that in the Carrot file it gives compilation error
– Gabriel Borin Macedo
Show the actual command you are using.
– user28595
for the Carroteste file, I used both javac Carroteste.java and javac -d .. Carroteste.java
– Gabriel Borin Macedo
When files are dependent on others, you cannot compile separately like this, you need to compile them in order from those that do not depend on others to those that depend, or all together. That must be the reason for the mistake, of course, but if you don’t explain completely how you are working it is difficult to help.
– user28595
so I tried to do these two measures, but it was wrong in the same way
– Gabriel Borin Macedo
Ask the question the commands you use to try to compile exactly the way you type them just like that.
– Victor Stafusa
@Articuno Martelei the question. Agree?
– Victor Stafusa
@Victorstafusa agree, for the author’s lack of clarity, I believe it is the same problem as the other question.
– user28595