![](/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.