Doubt about using packages in java

Asked

Viewed 37 times

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?

  • 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

  • 1

    Show the actual command you are using.

  • for the Carroteste file, I used both javac Carroteste.java and javac -d .. Carroteste.java

  • 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.

  • so I tried to do these two measures, but it was wrong in the same way

  • Ask the question the commands you use to try to compile exactly the way you type them just like that.

  • @Articuno Martelei the question. Agree?

  • @Victorstafusa agree, for the author’s lack of clarity, I believe it is the same problem as the other question.

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.