import java.awt.Color;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.*;public class Test2 {
public static void main(String[] args) {
new MyFrame(400,400,500,500,"LL");
}
}class MyFrame extends Frame{
private Panel p1,p2,p3,p4;
public MyFrame(int x,int y,int length,int width,String s) {
super(s);
p1 = new Panel();
p2 = new Panel();
p3 = new Panel();
p4 = new Panel();
p1.setBounds(0, 0, length/2, width/2);
p1.setBackground(Color.RED);
p2.setBounds(x/2, 0, length/2, width/2);
p2.setBackground(Color.BLACK);
p3.setBounds(0, y/2, length/2, width/2);
p3.setBackground(Color.YELLOW);
p4.setBounds(x/2, y/2, length/2, width/2);
p4.setBackground(Color.YELLOW);
this.add(p1);
this.add(p2);
this.add(p3);
this.add(p4);
this.setVisible(true);
}
}错误信息:Exception in thread "main" java.lang.NoSuchMethodError: MyFrame.<init>(IIIILjava/lang/String;)V
at Test2.main(Test2.java:8)

解决方案 »

  1.   

    看错误信息是
    Exception in thread "main" java.lang.NoSuchMethodError: MyFrame. <init>(IIIILjava/lang/String;)V 也就是说没找到MyFrame的构造方法.
    确定MyFrame.class  和Test2.class在一起吧.
    很奇怪的问题
      

  2.   

    IDE的BUG哇  如果是NetBeans的话 把project整个删掉 重建会解决。
    如果是eclipse的话  直接把这个类拖到其他的project里面  也会解决。
      

  3.   

    classpath下有两个 MyFrame.class
    改了改名字就O了