天天看點

Java架構錯誤

Eclipse “cannot be resolved to a type” error

​​http://chenxiaohu612.blog.163.com/blog/static/192214286201171004911955/​​

 ​​http://zhaoningbo.iteye.com/blog/1137215​​

引言: 

    eclipse新導入的項目經常可以看到“XX cannot be resolved to a type”的報錯資訊。本文将做以簡單總結。 

正文: 

    (1)jdk不比對(或不存在) 

    項目指定的jdk為“jdk1.6.0_18”,而目前eclipse使用的是“jdk1.6.0_22”。需要在BuildPath | Libraries,中做簡單調整。 

    (2)jar包缺失或沖突 

    當找不到“XX”所在的jar包時,會報這個錯。解決隻需要找到(ctrl+點選,可能能看到jar包名稱)對應jar包導入項目即可。 

    另外,出現相同的XX時也會報此錯。可能需要調包、解包、選删。 

    (3)eclipse查找項目類型政策所緻 

    eclipse下,上述兩條都對比過了,沒有任何問題,可偏偏還報這錯。這時,需要操作一下 Project | Clean... ,問題即可解決。原因是,機制所緻。因為某些特殊原因,eclipse沒能自動編譯源代碼到build/classes(或其他classes目錄),導緻類型查找不到。 

Based on the comments here, I started checking how I could make sure that my Ant build 

wouldn’t interfere with my Eclipse build.

I found an option in Eclipse that clears up the problem (and is possibly more efficient than

 changing the 2 build system’s output folders).

Windows–>Preferences–>Java–>Compiler–>Building–>Output folder–>