无法创建对象
Can't create a Object
我有一个包含多个 classes 的应用程序:
MenuActivity, MenuThread, MenuView, MenuBot, MenuBall.
在class "MenuView"中我声明了我需要的所有ib对象:
this.ball = new MenuBall(this, bot1);
this.bot1 = new MenuBot1(this, ball);
this.thread = new MenuThread(this,bot1,ball);
如您所见,我还没有创建对象 bot1,但我已经将它用作对象 ball 中的参数,这给了我错误。
感谢您的帮助!
您必须更改(或添加其他)MenuBall 和 MenuBot1 的构造函数。
因此,例如:
public class MenuBall {
private MenuBot1 menuBot1;
(...)
// this constructor doesn't need a MenuBot1 object.
public MenuBall(MenuView menuView) {
(...)
}
// setter for the menuBot1
public void setMenuBot1(MenuBot1 menuBot1) {
this.menuBot1 = menuBot1;
}
(...)
}
public class MenuBot1 {
private MenuBall menuBall;
(...)
// this constructor doesn't need a MenuBall object.
public MenuBot1(MenuView menuView) {
(...)
}
// setter for the menuBall
public void setMenuBall(MenuBall menuBall) {
this.menuBall = menuBall;
}
(...)
}
然后在菜单视图中class:
ball = new MenuBall(this);
bot1 = new MenuBot1(this);
ball.setMenuBot1(bot1);
bot1.setMenuBall(ball);
thread = new MenuThread(this, bot1, ball);
(...)
我有一个包含多个 classes 的应用程序:
MenuActivity, MenuThread, MenuView, MenuBot, MenuBall.
在class "MenuView"中我声明了我需要的所有ib对象:
this.ball = new MenuBall(this, bot1);
this.bot1 = new MenuBot1(this, ball);
this.thread = new MenuThread(this,bot1,ball);
如您所见,我还没有创建对象 bot1,但我已经将它用作对象 ball 中的参数,这给了我错误。
感谢您的帮助!
您必须更改(或添加其他)MenuBall 和 MenuBot1 的构造函数。 因此,例如:
public class MenuBall {
private MenuBot1 menuBot1;
(...)
// this constructor doesn't need a MenuBot1 object.
public MenuBall(MenuView menuView) {
(...)
}
// setter for the menuBot1
public void setMenuBot1(MenuBot1 menuBot1) {
this.menuBot1 = menuBot1;
}
(...)
}
public class MenuBot1 {
private MenuBall menuBall;
(...)
// this constructor doesn't need a MenuBall object.
public MenuBot1(MenuView menuView) {
(...)
}
// setter for the menuBall
public void setMenuBall(MenuBall menuBall) {
this.menuBall = menuBall;
}
(...)
}
然后在菜单视图中class:
ball = new MenuBall(this);
bot1 = new MenuBot1(this);
ball.setMenuBot1(bot1);
bot1.setMenuBall(ball);
thread = new MenuThread(this, bot1, ball);
(...)