![](/img/trans.png)
[英]android error: “The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (new OnClickListener(){})”
[英]The method call(Activity) in the type <type> is not applicable for the arguments (new View.OnClickListener(){})
在黑暗中摸索...這次我在Eclipse中收到以下錯誤:
IntentsUtils類型的方法call(Activity)不適用於參數(new View.OnClickListener(){})
此錯誤是指在擴展Activity的類中,回調函數中與按鈕相關的call()行:
public class UnderstandingIntents extends Activity {
...
...
...
// A call-back for when the user presses the testintents button.
OnClickListener mTestIntentsListener = new OnClickListener() {
public void onClick(View v) {
IntentsUtils.call(this);
}
};
}
IntentsUtils是一個從清單3-33逐字復制的類。
這個錯誤是什么意思?
這里的問題是,您試圖在匿名內部類中引用活動類(UnderstandingIntents),因此當您說“ this”時,它是指View.OnClickListener(){}
要更正此問題,請執行以下代碼:
IntentsUtils.call(UnderstandingIntents.this);
這樣,您的Activity類就被引用了。
傳遞給IntentsUtils.call()
的this
參數引用在其中使用它的對象,在這種情況下為OnClickListener
的實例。 嘗試用UnderstandingIntents.this
Intents.this替換this
參數:
IntentsUtils.call(UnderstandingIntents.this);
嘗試這個
IntentsUtils.call(UnderstandingIntents.this);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.