Eclipse “Import cannot be resolved” error

本文针对Eclipse中出现的Import cannot be resolved错误提供了解决方案。错误表现为已存在的包被误报告为未找到。文章提供了多种修复方法,包括清理项目、刷新文件夹、重建项目等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


Eclipse “Import cannot be resolved” error

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!

转至:http://blog.sherifmansour.com/?p=207

今天遇到的问题,包明明存在却突然报找不到包的错误,重启eclipse无法解决,Refresh也不行。最后是通过Project-Clean解决掉的。上面是一篇文章,列举了一系列的方法。


Description Resource Path Location Type AfterEach cannot be resolved to a type MetroTicketTest.java /aa/src/aa line 15 Java Problem BeforeEach cannot be resolved to a type MetroTicketTest.java /aa/src/aa line 11 Java Problem Syntax error on token "*", delete this token MetroTicketTest.java /aa/src/aa line 3 Java Problem Test cannot be resolved to a type MetroTicketTest.java /aa/src/aa line 19 Java Problem Test cannot be resolved to a type MetroTicketTest.java /aa/src/aa line 29 Java Problem Test cannot be resolved to a type MetroTicketTest.java /aa/src/aa line 36 Java Problem Test cannot be resolved to a type MetroTicketTest.java /aa/src/aa line 43 Java Problem Test cannot be resolved to a type MetroTicketTest.java /aa/src/aa line 50 Java Problem Test cannot be resolved to a type MetroTicketTest.java /aa/src/aa line 57 Java Problem Test cannot be resolved to a type MetroTicketTest.java /aa/src/aa line 64 Java Problem Test cannot be resolved to a type MetroTicketTest.java /aa/src/aa line 71 Java Problem Test cannot be resolved to a type MetroTicketTest.java /aa/src/aa line 78 Java Problem Test cannot be resolved to a type MetroTicketTest.java /aa/src/aa line 86 Java Problem Test cannot be resolved to a type MetroTicketTest.java /aa/src/aa line 94 Java Problem Test cannot be resolved to a type MetroTicketTest.java /aa/src/aa line 102 Java Problem Test cannot be resolved to a type MetroTicketTest.java /aa/src/aa line 110 Java Problem Test cannot be resolved to a type MetroTicketTest.java /aa/src/aa line 118 Java Problem Test cannot be resolved to a type MetroTicketTest.java /aa/src/aa line 126 Java Problem The method assertEquals(String, String) is undefined for the type MetroTicketTest MetroTicketTest.java /aa/src/aa line 27 Java Problem The method assertEquals(String, String) is undefined for the type MetroTicketTest MetroTicketTest.java /aa/src/aa line 34 Java Problem The method assertEquals(String, String) is undefined for the type MetroTicketTest MetroTicketTest.j
03-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值