Exception in thread "main" java.lang.Error: Unresolved compilation problems:
按书上做了一个简单的窗口+按钮GUI。。。然后报错了。。importjavax.swing.*;publicclasstest{/***@paramargs*/publi...
按书上做了一个简单的窗口+按钮GUI。。。然后报错了。。
import javax.swing.*;
public class test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame frame = new JFrame();
JButton button = new JButton("click me");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(button);
frame.setSize(300, 300);
frame.setVisible(true);
}
}
然后报错是:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The type javax.swing.JComponent cannot be resolved. It is indirectly referenced from required .class files
The method add(Component) in the type Container is not applicable for the arguments (JButton)
at test.main(test.java:18)
我看网上大家说的,要么是jar包不完整,要么就是JRE路径没设对。。。然后我各种改JRE路径还是报错。。。唉,这是什么原因呢? 展开
import javax.swing.*;
public class test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame frame = new JFrame();
JButton button = new JButton("click me");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(button);
frame.setSize(300, 300);
frame.setVisible(true);
}
}
然后报错是:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The type javax.swing.JComponent cannot be resolved. It is indirectly referenced from required .class files
The method add(Component) in the type Container is not applicable for the arguments (JButton)
at test.main(test.java:18)
我看网上大家说的,要么是jar包不完整,要么就是JRE路径没设对。。。然后我各种改JRE路径还是报错。。。唉,这是什么原因呢? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询