Eclipse “Import cannot be resolved” error

보통은 아래에 빨갛게 칠해진 세 가지면, 해결된다. 

같은 방법인데도, 한번 해서 안될 때가 있고, 두 세번 해주면 될 때가 있다.

프로젝트가 꼬이고, jar 파일을 찾지못하고, 임포트 에러를 내뿜을 때는, 아래 세가지를 될 때까지 반복하자 ㅡㅡ; 





by
Sherif

I’m amazed at how many shortcuts or different ways there are of doing things in Eclipse.

Recently I kept hitting an issue of Eclipse not recognising my imports (even though they were there). I was always getting the message:

import ClassName cannot be resolved.

Where ClassName was my imported class. I’m using the MyEclipse Workbench 5.5.1 on Eclipse 3.2. Here are a few tips on how you can fix this (some worked for me, some didn’t):

  • ‘Clean’ Your Eclipse Project: Go to Project > Clean in Eclipse [This seems to work for me]
  • Refresh your project folder (right click on your project > refresh)
  • Re-build your project
  • Clean your builds (If using Ant or Maven – clean your builds)
  • Recreate your project in Eclipse
  • ‘Switch’ Workspace – then Switch back (Eg Change to Debug, then switch back to Java)
  • ‘Switch’ Workspace – then Switch back (Eg Change to Debug, then switch back to Java)
  • Remove and re-add your JRE:
    1. Right Click on your project > properties
    2. Click on the Libraries tab
    3. Click on the JRE
    4. Click remove, then OK
    5. Repeat 1-3 again, but add the JRE again

Hope at least ONE of those tips help!