简体   繁体   中英

java cannot resolve imports

Some time ago I made a java project for my programming subject, developed in Eclipse. I tested it many times and worked flawlessly. However in the exam's computer didn't, I tried to compile it and returned 16 errors. Now back to my computer I deleted the .class files and compiled again manually returning the same 16 errors. I opened up eclipse to try compile it from within eclipse like the very first time and now shows these errors, I didn't change anything in the code...

Said errors are all the same, missing symbols. The errors are produced when trying to compile one class out of 6 in the package ("Contacto" class). This class uses 4 out of the other 5 classes and there is where the error is produced. One error for each line where one of this 4 classes is used. Eclipse points out the same error and gives a quick fix, importing the missing class, but if I don't remeber badly you don't need to import classes that are located in the same package of the one that are being used at. Anyway I tried importing the suggested class and it produces another error in eclipse (The import 'package name' cannot be resolved) so I don't know what else to try...

The project setup seems fine to me (it even worked once...)

The code is quite simple but quite long also so I will post as few as possible.

package fp2.poo.pfpooferdomdel1;

import fp2.poo.utilidades.ContactoInterfaz;
import fp2.poo.utilidades.CorreoElectronicoInterfaz;
import fp2.poo.utilidades.DomicilioInterfaz;
import fp2.poo.utilidades.PersonaInterfaz;
import fp2.poo.utilidades.TelefonoInterfaz;
import fp2.poo.pfpooferdomdel1.CorreoElectronico;  //Tried to import the missing class here, returned error: The import fp2.poo.pfpooferdomdel1.CorreoElectronico cannot be resolved


public class Contacto implements ContactoInterfaz
    {
    CorreoElectronico correo = new CorreoElectronico();  //Error here, missing "CorreoElectronico"
    Domicilio domicilio = new Domicilio();
    Persona persona = new Persona();
    Telefono telefono = new Telefono();

The same error goes for the following 3 lines, missing symbols for Domicilio, Persona and Telefono.

One of the errors returned by the console

`javac -Xlint -encoding ISO-8859-1 -classpath ./bin  -cp ./bin -d ./bin  ./src/fp2/poo/pfpooferdomdel1/Contacto.java
.\src\fp2\poo\pfpooferdomdel1\Contacto.java:8: error: cannot find symbol
import fp2.poo.pfpooferdomdel1.CorreoElectronico;;
                              ^
  symbol:   class CorreoElectronico
  location: package fp2.poo.pfpooferdomdel1
.\src\fp2\poo\pfpooferdomdel1\Contacto.java:19: error: cannot find symbol
        CorreoElectronico correo = new CorreoElectronico();
        ^`

Makefile for Contacto.java (it was given by the teachers)

     JAVAC=javac
     JAVA=java
     lsJAR=jar
     OPCIONES= -Xlint -encoding ISO-8859-1 -classpath ./bin  -cp ./bin -d ./bin 
    ./bin/fp2/poo/pfpooferdomdel1/Contacto.class: \
                   ./bin/fp2/poo/utilidades/TelefonoInterfaz.class \
                   ./bin/fp2/poo/utilidades/PersonaInterfaz.class \
                  ./bin/fp2/poo/utilidades/DomicilioInterfaz.class \
                   ./bin/fp2/poo/utilidades/CorreoElectronicoInterfaz.class \
                   ./bin/fp2/poo/utilidades/ContactoInterfaz.class \
                   ./src/fp2/poo/pfpooferdomdel1/Contacto.java
$(JAVAC) $(OPCIONES) ./src/fp2/poo/pfpooferdomdel1/Contacto.java

This particular code file is located at ./src/fp2/poo/pfpooferdomdel1/ which I think is consistent with the package name.

Project setup

./src/fp2/poo>$ ls
datos  pfpooferdomdel1  principal  utilidades
./src/fp2/poo/pfpooferdomdel1>$ ls
Agenda.java  Contacto.java  CorreoElectronico.java  Domicilio.java  Persona.java  Telefono.java
./src/fp2/poo/principal>$ ls
Principal.java

There are more folders and files but I don't think they are relevant.

If anything else is required please do not hesitate to ask it.

Thanks in advance.

It appears the CorreoElectronico.java file is missing. It should be in the ./src/fp2/poo/pfpooferdomdel1 directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM