supertosti
supertosti

Reputation: 35

Java classes and packages

Hello everybody I am a beginner of Java. I am blocked at this point with the following program:

import prog.io.Orario;
import prog.io.ConsoleOutputManager;
class primoprogramma{

    public static void main(String[] args){
        ConsoleOutputManager video=new ConsoleOutputManager();
        video.println("ciao");
    }
}

That gives me the error:

bad class file: ./prog/io/Orario.class
class file contains wrong class: prog.utili.Orario

Please remove or make sure it appears in the correct subdirectory of the classpath.

I did everything I could tried in those days but nothing works. Here there the class Orario:

package prog.utili;
public class Orario {
    private static char separaratore=';';
}

Thank you for any advice

Upvotes: 2

Views: 142

Answers (2)

Arne Burmeister
Arne Burmeister

Reputation: 20614

Your class Orario has the wrong package declaration (package prog.utili; instead of package prog.io;)

  1. The compiler scans your import of prog.io.Orario.
  2. It searches for class Orario in a file Orario.class in directory prog/io.
  3. The class found has the package prog.utili declared which is not the desired one - Error

Upvotes: 4

deviantfan
deviantfan

Reputation: 11434

In java, directorys are the same as package names.
So, a class Orario in the package prog.utili
have to be in a directory prog/utili instead of prog/io

Upvotes: 1

Related Questions