[英]JFrame is not recognised by eclipse
I am trying to create an example with JFrame, but when i write JFrame in eclipse, it gets underscored by red line as if it is not defined, how can I solve this issue: 我正在尝试使用JFrame创建一个示例,但是当我在Eclipse中编写JFrame时,如果未定义它,则用红线强调它,我该如何解决此问题:
code : 代码 :
package openCVExamples;
public class OpenCVTest {
public static void main(String[] args) {
JFrame j = new JFrame();
}
}
update : 更新 :
when hover over JFrame keyword, eclipse says 当将鼠标悬停在JFrame关键字上时,eclipse会说
:Access restriction: the type
JFrame is not accessible due to restriction on required library
c:?\programfiles\java\jre1.8.0_40\lib\rt.jar
Most likely; 最有可能的; you did not import the JFrame class.
您没有导入 JFrame类。
You can simply press "ctrl-shift-o" to "organize" your import statements. 您只需按“ ctrl-shift-o”即可“组织”您的导入语句。 Eclipse will automatically add all required imports.
Eclipse将自动添加所有必需的导入。
JFrame is a class that belongs to the "default" set of classes for Java. JFrame是一个类,它属于Java的“默认”类集。 If it can't be found/imported, then your "project setup" is broken somehow.
如果找不到/导入,则您的“项目设置”会以某种方式损坏。
You have to import the JFrame class. 您必须导入JFrame类。 You can write:
你可以写:
package OpenCVExamples;
import javax.swing.*;
public class OpenCVTest{
//your code
}
at the top of your file, but after the package line. 在文件顶部,但在打包行之后。
You can also do it automatically by pressing Ctrl+Shift+O to import all the classes you need. 您也可以通过按Ctrl + Shift + O导入所需的所有类来自动执行此操作。
Project -> Properties -> Libraries
项目->属性->库
Remove the rt.jar file
删除rt.jar文件
Click on "Add external JARs.."
单击“添加外部JAR”。
Re-add the rt.jar file (located at C:\\Program Files\\Java\\jre1.8.0_20\\lib)
重新添加rt.jar文件(位于C:\\ Program Files \\ Java \\ jre1.8.0_20 \\ lib)
If it still does not work, you might want to try a different Java Runtime Environment. 如果仍然无法运行,则可能要尝试其他Java运行时环境。 I had the same problem and what fixed it for me was importing the rt.jar file located at C:\\Program Files\\Java\\jre7\\lib.
我遇到了同样的问题,并且为我解决的问题是导入位于C:\\ Program Files \\ Java \\ jre7 \\ lib的rt.jar文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.