![](/img/trans.png)
[英]Constructor call must be the first statement in a constructor in super()
[英]Constructor Call must be the first statement in a constructor while using super();
这个super()的替代品是什么? 我的代码中的语句...因为它向我显示了一个错误:构造函数调用必须是构造函数中的第一条语句。
class c
implements android.view.View.OnClickListener
{
final b a;
private final Dialog b;
c(b b1, Dialog dialog)
{
a = b1;
b = dialog;
**super();**//Error Constructor Call must be the first statement in a constructor
}
public void onClick(View view)
{
b.cancel();
}
}
它应该是:
c(b b1, Dialog dialog) {
super();
a = b1;
b = dialog;
}
将c更改为此:
c(b b1, Dialog dialog) {
super();
a = b1;
b = dialog;
}
如果调用超类构造函数,则必须始终在进行自己的初始化之前执行此操作。
为了方便起见,您还可以更改变量名称,例如:
class C implements android.view.View.OnClickListener {
final B a;
private final Dialog b;
c(B a, Dialog b) {
super();
this.a = a;
this.b = b;
}
public void onClick(View view) {
b.cancel();
}
}
super();
指扩展类的构造函数,即Object
..
为避免出现此类错误,请修改您的代码,使super();
应该是c
类构造函数中的第一条语句。
c(b b1,Dialog dialog)
{
super();
a = b1;
b = dialog;
}
PS您的编译器本身会为您提供答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.