我有这段代码:
public class Profile extends Container{
public Profile(String value) {
Container profilo_1 =new Container();
Container profilo_2 =new Container();
// (1) THIS ADD A BUTTON TO THE MAIN CLASS
this.createButton().setLabel("Modifica Profilo");
// (2) NOW I NEED TO ADD A BUTTON INTO THE INSTANCE OF profilo_2 BUT IT FAILS
profilo_2.add(this.createButton());
this.add(profilo_1);
this.add(profilo_2);
}
}
第(2)点失败,因为它说我要向此容器添加一个子容器,但它已经是容器的所有者...
事实上,如果我这样做:
ILabel label=new ILabel();
profilo_2.add(label);
它告诉我 ILabel() 是抽象的,无法实例化!
我该如何解决这个问题?为大家干杯:)
最佳答案
疯狂猜测,因为这取决于你的代码......试试这个(更不用说 Piotr 所说的了)
profilo_2.add(profilo_2.createButton());
关于Java - 在另一个实例中添加抽象类的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4155625/