[英]The method call(Activity) in the type <type> is not applicable for the arguments (new View.OnClickListener(){})
Groping in the dark... This time I am receiving the following error in Eclipse: 在黑暗中摸索...这次我在Eclipse中收到以下错误:
The method call(Activity) in the type IntentsUtils is not applicable for the arguments (new View.OnClickListener(){})
IntentsUtils类型的方法call(Activity)不适用于参数(new View.OnClickListener(){})
This error refers to the call() line in a callback hooked up to a button, in a class that extends Activity: 此错误是指在扩展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 is a class copied verbatim from listing 3-33 here . IntentsUtils是一个从清单3-33逐字复制的类。
What does this error mean? 这个错误是什么意思?
The problem here is that you are trying to reference the Activity Class (UnderstandingIntents) in an Anonymous inner class, hence when you say "this" it refers to View.OnClickListener(){} 这里的问题是,您试图在匿名内部类中引用活动类(UnderstandingIntents),因此当您说“ this”时,它是指View.OnClickListener(){}
to correct this do the following code: 要更正此问题,请执行以下代码:
IntentsUtils.call(UnderstandingIntents.this);
This way, your Activity class gets referenced. 这样,您的Activity类就被引用了。
The this
parameter passed into IntentsUtils.call()
refers to the object within which it is being used, in this case an instance of OnClickListener
. 传递给
IntentsUtils.call()
的this
参数引用在其中使用它的对象,在这种情况下为OnClickListener
的实例。 Try replacing the this
parameter with UnderstandingIntents.this
: 尝试用
UnderstandingIntents.this
Intents.this替换this
参数:
IntentsUtils.call(UnderstandingIntents.this);
尝试这个
IntentsUtils.call(UnderstandingIntents.this);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.