是什么导致此Java“找不到符号”错误?

我正在修改继承的代码,并不断收到奇怪的“找不到符号”错误,这使我不知所措。

   //======= 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

同行车:

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);

}

}

}

公司简介:

   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);

}

}

我已经三重检查,但到目前为止找不到任何错误的代码。我正在Netbeans

7.0.1中构建它。我应该提到在构建时遇到此错误,但是我可以运行Web应用程序而没有任何问题(尚未)。但是我担心这种情况可能会重新出现在后面。


我只是在文件树中注意到,在CompanyDAO类上方是类似命名的文件,其格式为:CompanyDAO $

ChildType#.class(#对应于一个数字)我猜它还没有重新编译该类以生成额外的我添加了子类型。我该怎么做?

回答:

在CarPeer之前,CompanyDao是否已在类路径上编译并可用?

以上是 是什么导致此Java“找不到符号”错误? 的全部内容, 来源链接: utcz.com/qa/405042.html

回到顶部