不兼容的类型: <匿名OnClickListener>无法转换为Context

遇到的问题Error:Execution failed for task ':app:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

代码如下
package com.example.notificationtest1;

import android.app.Notification;
import android.app.NotificationManager;
import android.graphics.BitmapFactory;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button sendNotice = (Button) findViewById(R.id.send_notice);
    sendNotice.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            NotificationManager manager = (NotificationManager)
                    getSystemService(NOTIFICATION_SERVICE);
            Notification notification = new NotificationCompat.Builder(this)
                    .setContentTitle("This is content title")
                    .setContentText("This is content text")
                    .setWhen(System.currentTimeMillis())
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
                    .build();
            manager.notify(1,notification);
        }
    });
}

}
就是在 Notification notification = new NotificationCompat.Builder(this)这一句里面的this出错了,在使用按钮控件的时候设置监听器也会,
Button button = (Button) findViewByid(R.id.button1);
button.setOnClickListener(this)也会出现类似的问题,求哪位大佬帮忙解释下~

class A{ #在此作用域内的所以this都是指 new A()这个对象。#}
new View.OnClickListener() {
@Override
public void onClick(View view) {
#此处this指 new View.OnClickListener()对象#
}
};
new NotificationCompat.Builder(context);括号里需要传递context,而楼主传的是 new View.OnClickListener()对象,显然会报错。
解决办法:1,在onCreate方法中直接 mContext = this;#此处this是activity,activity是Context的实现类(暂且认为子类)#
new NotificationCompat.Builder(mContext);
2.new NotificationCompat.Builder(MainActivity.this);#内部类(除静态内部类)都可以获取其外部类的引用 ClassName.this#

你activity没有去implement监听 ,像这个MainActivity extends FragmentActivity implements View.OnClickListener{ } 这个监听没写implements View.OnClickListene

this关键字,表示的是当前对象,你在onClickListener中使用,this指代的是当前的onClickListener,如果你想使用外部的类,例如你想使用Activity,得修改成:

 sendNotice.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            NotificationManager manager = (NotificationManager)
                    getSystemService(NOTIFICATION_SERVICE);
            Notification notification = new NotificationCompat.Builder(MainActivity.this)
                    .setContentTitle("This is content title")
                    .setContentText("This is content text")
                    .setWhen(System.currentTimeMillis())
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
                    .build();
            manager.notify(1,notification);
        }
    });

会不会是导包的问题?button.setOnClickListener(this)也会出现类似的问题,那你试试将this改为MainActivity.this 正常情况下不会出现你这种问题

上面提到问题用MainActivity.this,但是按钮那里还是不行,怎么破,,图片说明