What causes the Java "Cannot find character" error?

I modify the inherited code and keep getting the weird “can't find character” error that throws me away.

//======= 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 checked triple, but still can not find anything bad in the code. I create it in Netbeans 7.0.1. I should mention that I get this error on creation, but I can run the web application without any problems (for now). But I'm worried that it might come back to bite after itself.


I just noticed in the file tree that the CompanyDAO classes have similar file names with the format: CompanyDAO $ ChildType # .class (# matches the number) I assume that he did not recompile the class to generate an additional child type I added. How can i do this?

+6
source share
6 answers

Is compiling and accessing CompanyDao going to the class path to CarPeer?

+2
source

Most likely you are using a previously compiled class file (which does not have a method) in your class path, and the system is trying to use this instead of your current source code.

Otherwise, clear the workspace, not depending on existing compilations, and try again. It happened to me in the past.

+6
source

I have the same problem (although I don’t know for the same reason). For me, the only thing that works (except that it is a "reliable" IDE) is to remove the cache. In windows, it is located in %UserProfile%\.netbeans\7.0\var\cache . I suggest that on * nix this could be under ~/.netbeans/7.0/var/cache . You must first exit NetBeans, delete the cache, and then start NetBeans again.

+4
source

Clean and create your project. If this does not work, restart Netbeans. Sometimes Netbeans gives strange errors and a complete restart of Netbeans and / or the computer seems to fix these inexplicable problems.

+1
source

If using Netbeans 7.2+, do the following:

  • Close all tabs and exit Netbeans;
  • Delete cache directory: ~ / .cache / netbeans / VERSION. Where VERSION is the version of Netbeans, i.e. 7.3.1
  • Restart NetBeans and Clean and Build

Also see How to Clear Cache in NetBeans

+1
source

This can be a problem because the current netbeans instance that you are using uses the previously created cache during its initialization. So, to clear the netbeans cache, you can do either of these two steps, listed below.

APPROACH 1
1. Right-click the name of your project in netbeans on the Projects tab.
2. Click the clear and build button.
3. The cache has been cleared.

APPROACH 2
1. Press "Windows key + R" and enter "% UserProfile% / appdata / local / netbeans".
2. Go to the cache folder, and then to the folder with the name that defines the version of netbeans.
3. Close Netbeans and delete all files in the folder.
4. Reboot netbeans and you can now see the class name.

If any of these methods does not work, then your class path may be incorrect.

0
source

Source: https://habr.com/ru/post/902574/


All Articles