简体   繁体   中英

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:

The method call(Activity) in the type IntentsUtils is not applicable for the arguments (new View.OnClickListener(){})

This error refers to the call() line in a callback hooked up to a button, in a class that extends Activity:

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 .

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(){}

to correct this do the following code:

IntentsUtils.call(UnderstandingIntents.this); 

This way, your Activity class gets referenced.

The this parameter passed into IntentsUtils.call() refers to the object within which it is being used, in this case an instance of OnClickListener . Try replacing the this parameter with UnderstandingIntents.this :

IntentsUtils.call(UnderstandingIntents.this);

尝试这个

IntentsUtils.call(UnderstandingIntents.this);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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