是什么原因导致此Java“找不到符号"?错误? [英] What is causing this Java "Cannot find symbol" error?
问题描述
我正在修改继承的代码,并不断收到奇怪的找不到符号"错误,这使我无法自拔.
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
同伴:
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:
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);
}
}
我已经进行了三重检查,但到目前为止找不到任何错误的代码.我正在Netbeans 7.0.1中构建它.我应该提到在构建时遇到此错误,但是我可以运行Web应用程序而没有任何问题(尚未).但我担心这种情况可能会重新出现在后面.
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.
我刚刚在文件树中注意到,在CompanyDAO类之上是类似命名的文件,其格式为:CompanyDAO $ ChildType#.class(#对应于一个数字)我猜它还没有将类重新编译为生成我添加的额外子类型.我该如何实现?
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?
推荐答案
在CarPeer之前,CompanyDao是否已在类路径上编译并可用?
Is CompanyDao being compiled and available on the classpath before CarPeer?
这篇关于是什么原因导致此Java“找不到符号"?错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!