Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I got " cannot be resolved to a type" error?

Tags:

java

eclipse

I am developing a dynamic web project (RESTful jersey) under Eclipse IDE.

Under src/my/demo/service folder I have CarService.java class

public class CarService {
  ...
}

Under src/my/demo/controller folder I have UserController.java class

import my.demo.service.CarService;

public class UserController{
    private CarService carService; //ERROR: CarServcie cannot be resolved to a type
    
}

I do have imported the CarService, why eclipse give me the error "CarServcie cannot be resolved to a type" in my UserController.java?

--------Edit------------------

I found the cause: for some reason, my.demo.service has the same level as src/ in eclise project explorer view. After I move my.demo.service under src/, it is fine. Seems I should not create new package in "Project Explorer" view in Eclipse.

like image 875
Mellon Avatar asked Apr 07 '11 10:04

Mellon


Video Answer


2 Answers

You probably missed package declaration

package my.demo.service;
public class CarService {
  ...
}
like image 191
jmj Avatar answered Oct 22 '22 16:10

jmj


u just need go to Project ---> clean See http://philip.yurchuk.com/2008/12/03/eclipse-cannot-be-resolved-to-a-type-error/

like image 36
Bardelman Avatar answered Oct 22 '22 15:10

Bardelman