Maison > Java > javaDidacticiel > le corps du texte

使用eclipse写JAVA出现xxx cannot be resolved to a type错误的解决方法详解

黄舟
Libérer: 2017-03-17 10:34:38
original
5375 Les gens l'ont consulté

这篇文章主要介绍了java eclipse 出现 xxx cannot be resolved to a type 错误解决方法的相关资料,需要的朋友可以参考下

xxx cannot be resolved to a type

引言    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目录),导致类型查找不到。 

编码问题

以上这些是比较常见的错误,我这里遇到的错误是文件编码导致的!

错误类似下图,这里只截取一部分:

使用eclipse写JAVA出现xxx cannot be resolved to a type错误的解决方法详解

解决方法:

在发生错误的项目上单击鼠标右键》Properties

使用eclipse写JAVA出现xxx cannot be resolved to a type错误的解决方法详解

左侧选中“Resource”,右侧Text file encoding选择“Other:UTF-8”,点击“Apply”按钮

使用eclipse写JAVA出现xxx cannot be resolved to a type错误的解决方法详解

很多小伙伴反馈,经过上面的步骤还是不能解决问题,刚好最近遇到这样的问题;

在文章 Java中REST API使用示例——基于云平台+云服务打造自己的在线翻译工具 中从IBM Bluemix上下载的Java示例代码,导入到Eclipse之后,出现类似以上错误信息!如下图:

使用eclipse写JAVA出现xxx cannot be resolved to a type错误的解决方法详解

具体解决方法请参考:HttpServlet cannot be resolved to a type

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!