I'm modifying inherited code and keep getting a weird "cannot find symbol" error which is throwing me off.
//======= Error =========
Compiling 1 source file to /Users/Inprimus/Projects/Workspace/Soft/build/web/WEB-INF/classes
/Users/Inprimus/Projects/Workspace/Soft/WebContent/WEB-INF/classes/fr/service/CarPeer.java:49: cannot find symbol
symbol : method addCarToCompany(java.lang.Long,fr.model.company.Car)
location: class fr.dao.CompanyDAO
cmpDAO.addCarToCompany(idCompany,car);
^
1 error
Car peer:
package fr.service;
import fr.model.company.Car;
import fr.dao.CompanyDAO;
import fr.dao.CarDao;
public class CarPeer {
private static CarDao carDAO= new CarDao();
private static CompanyDAO cmpDAO = new CompanyDAO();
public static void storeCar(Long idCompany, Car car) throws UserServiceException, Exception {
try {
cmpDAO.addCarToCompany(idCompany,car);
System.out.println("Car stored : "+car.toString()+" in "+idCompany);
carDAO.storeCar(car);
} catch(DAOException ex) {
throw new UserServiceException(ex.getMessage(), ex);
}
}
}
CompanyDao:
package fr.dao;
import fr.model.accounting.Cost;
import fr.model.company.Car;
public class CompanyDAO extends GenericDAO<Company> {
private enum ChildType {
COST{
public void addChildToCompany(Company company, Object child) {
company.addCost((Cost)child);
}
},
CAR{
public void addChildToCompany(Company company, Object child) {
company.addCar((Car)child);
}
};
public abstract void addChildToCompany(Company company, Object child);
}
private void addChildToCompany(Long idCompany, Object child, ChildType type) throws NotFoundDAOException, AlreadyExistDAOException, Exception {
try {
// Begin unit of work
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Company company = (Company) session.load(Company.class, idCompany);
type.addChildToCompany(company, child);
session.flush();
// End unit of work
session.getTransaction().commit();
} catch (ObjectNotFoundException ex) {
HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().rollback();
throw new NotFoundDAOException("Identified object " + idCompany
+ " doesn't exist in database", ex);
} catch (ConstraintViolationException ex) {
HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().rollback();
throw new AlreadyExistDAOException("The new identity already exsits in database", ex);
} catch (Exception ex) {
ex.printStackTrace();
HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().rollback();
throw new Exception(ex);
}
}
public CompanyDAO() {
super(Company.class);
}
public void addCarToCompany(Long idCompany, Car car) throws NotFoundDAOException, AlreadyExistDAOException, Exception {
addChildToCompany(idCompany, car, ChildType.CAR);
}
}
I have triple checked but can't find anything wrong with the code thus far. I am building it in Netbeans 7.0.1.I should mention that I get this error when I build, but I can run the web app with no issues whatsoever (yet). But I am worried this may come back to bite in the behind.
I just noticed in the file tree that above the CompanyDAO classes are similarly named files bearing the format: CompanyDAO$ChildType#.class (# corresponds to a number) I'm guessing it hasn't re-compiled the class to generate the extra child Type I added. How can I effect this?
Most likely you're using a previously compiled class file ( which didn't have the method ) in your classpath and the system is trying to use that instead of your current source code.
Otherwise, clean up your workspace, do not depend on existing compilations and try again. This has happened to me in the past.