简体   繁体   English

“导入java.awt无法解析”和“ *****无法解析为类型”

[英]“The import java.awt cannot be resolved” and “ ***** cannot be resolved to a type”

I downloaded a Java project that I want to study and learn some things from. 我下载了一个Java项目,我想学习并从中学习一些东西。 When I downloaded it on another computer it worked great, but when I try it on my computer, nearly every declaration and import is given the error message " * cannot be resolved to a type" or "The import java.awt cannot be resolved". 当我将其下载到另一台计算机上时,它工作得很好,但是当我在计算机上尝试它时,几乎每个声明和导入都收到错误消息“ *无法解析为类型”或“导入java.awt无法解析” 。

I did some research on this site and found that it might have to do with not having the latest Java installed. 我在此站点上进行了一些研究,发现可能与未安装最新的Java有关。 I checked mine, and I have JavaSE-1.7 (unbound). 我检查了我的,发现有JavaSE-1.7(未绑定)。 So I have the latest version but it's (unbound)? 所以我有最新版本,但是(未绑定)?

Can this be the problem? 这可能是问题吗? And what does (unbound) mean? (未绑定)是什么意思?

I'm using Eclipse 3.3.2 我正在使用Eclipse 3.3.2

UPDATE: I just found this error message at the top of the Properties window: org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7 . 更新:我只是在“属性”窗口的顶部发现了此错误消息: org.eclipse.jdt.launching.JRE_CONTAINER / org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType / JavaSE-1.7 What does this mean? 这是什么意思?

This occurs because project has dependency on library of J2SE 1.7 but it cannot find JRE at that location in your machine. 发生这种情况是因为项目依赖于J2SE 1.7库,但是无法在您计算机的该位置找到JRE。

Project->Properties->Java Build Path 项目->属性-> Java构建路径

Or Add a new JRE in eclipse using Window>Preferences>Java>Installed JRE and locate the path of the JRE folder in your machine. 或使用“ 窗口”>“首选项”>“ Java”>“已安装的JRE”在eclipse中添加新的JRE,并在计算机中找到JRE文件夹的路径。 and then replace the dependency of your project with the new JRE you installed in eclipse. 然后用在Eclipse中安装的新JRE替换项目的依赖项。

UPDATE UNBOUND JRE in Hello World 在Hello World中 更新 UNBOUND JRE

This may work for some... it did for me: 这可能对某些人有用...对我有用:

  1. Hover over "java.awt" in your code, and under quick fixes available , select Fix Project Setup . 将鼠标悬停在代码中的“ java.awt”上,然后在可用的快速修复下,选择“ 修复项目设置”

  2. Pop-up displays saying " The following proposals have been found... " and 弹出窗口显示“ 已找到以下建议... ”,然后
    " Add Library JRE System Library[JavaSE-1.7] to build path " is selected. 选择“ 添加库JRE系统库[JavaSE-1.7]以构建路径 ”。

  3. Select Ok. 选择确定。

Problem occurs because project has dependency on library of java 1.7 but it cannot find JRE at specified location in your machine. 发生问题是因为项目依赖于Java 1.7库,但是无法在计算机中的指定位置找到JRE。

Project->Properties->Java Build Path 项目->属性-> Java构建路径

Or Add a new JRE in eclipse using Window>Preferences>Java>Installed JRE and locate the path of the JRE folder in your machine. 或使用“窗口”>“首选项”>“ Java”>“已安装的JRE”在eclipse中添加新的JRE,并在计算机中找到JRE文件夹的路径。 and then replace the dependency of your project with the new JRE you installed in eclipse. 然后用在Eclipse中安装的新JRE替换项目的依赖项。 if teher is No JRE and click on add jre tab and provide the directory location of the Jre and add that. 如果teher为No JRE,则单击“添加jre”选项卡,并提供Jre的目录位置并添加。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM