繁体   English   中英

类型中的方法调用(活动) <type> 不适用于参数(新的View.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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM