简体   繁体   English

类型中的方法调用(活动) <type> 不适用于参数(新的View.OnClickListener(){})

[英]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.

相关问题 android错误:“视图类型中的方法setOnClickListener(View.OnClickListener)不适用于参数(new OnClickListener(){})” - android error: “The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (new OnClickListener(){})” 视图类型中的方法setOnClickListener(View.OnClickListener)不适用于自变量(新DialogInterface.OnClickListener(){}) - The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (new DialogInterface.OnClickListener(){}) 视图类型中的方法setOnClickListener(View.OnClickListener)不适用于参数() - The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments () 视图类型中的方法setOnClickListener(View.OnClickListener)不适用于自变量(起点) - The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (startingpoint) 类型View中的Java Android - setOnClickListener(View.OnClickListener)不适用于参数(new OnClickListener(){}) - Java Android - setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (new OnClickListener(){}) 类型View中的setOnClickListener(View.OnClickListener)不适用于参数(SequencerActivity)back.setOnClickListener(this); - setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (SequencerActivity) back.setOnClickListener(this); Android对于new View.OnClickListener(){}类型,未定义方法startActivity(Intent) - Android The method startActivity(Intent) is undefined for the type new View.OnClickListener(){} 未为类型imageButton1定义方法setOnClickListener(new View.OnClickListener(){}) - The method setOnClickListener(new View.OnClickListener(){}) is undefined for the type imageButton1 Android-未定义类型为new View.OnClickListener(){}的Sqlite数据库方法 - Android - Sqlite database method undefined for type new View.OnClickListener(){} 对于new View.OnClickListener(){}类型,未定义方法overridePendingTransition(int,int) - The method overridePendingTransition(int, int) is undefined for the type new View.OnClickListener(){}
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM