android NotificationCompat.Builder未定义

android NotificationCompat.Builder未定义,android,notifications,Android,Notifications,当我尝试将通知代码设置为按钮时 它总是给我这部分的错误 NotificationCompat.Builder mBuilder=新建NotificationCompat.Builder(此) [[构造函数NotificationCompat.Builder(new View.OnClickListener(){})未定义]] 我怎样才能解决这个问题 Button button9= (Button) findViewById(R.id.button9); button9.setOnClic

当我尝试将通知代码设置为按钮时 它总是给我这部分的错误

NotificationCompat.Builder mBuilder=新建NotificationCompat.Builder(此)

[[构造函数NotificationCompat.Builder(new View.OnClickListener(){})未定义]]

我怎样才能解决这个问题

Button button9= (Button) findViewById(R.id.button9);
    button9.setOnClickListener(new View.OnClickListener(){
    public void onClick(View arg0) {


        ///////////My Notification//////////////////////////        
        NotificationCompat.Builder mBuilder =new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.notification_icon)
        .setContentTitle("I'm astm  loooooooool")
        .setContentText("Hello baby to my world!");
        // Creates an explicit intent for an Activity in your app
        Intent resultIntent = new Intent(this, MainActivity.class);

        // The stack builder object will contain an artificial back stack for the
        // started Activity.
        // This ensures that navigating backward from the Activity leads out of
        // your application to the Home screen.
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        // Adds the back stack for the Intent (but not the Intent itself) (ResultActivity)
        stackBuilder.addParentStack(MainActivity.class);
        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(resultPendingIntent);
        NotificationManager mNotificationManager=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        int mId = 0;
        // mId allows you to update the notification later on.
        mNotificationManager.notify(mId, mBuilder.build());
        ///////////End Notification//////////////////////////
        }
    });

谢谢大家帮我[[没人给我任何答案looooool]]

我自己得到了答案 只需将NotificationCompat.Builder定义为Final,它就工作得很好

^__^


我也有同样的问题。我改变了:

NotificationCompat.Builder mBuilder =new NotificationCompat.Builder(this)
与:


使用
getBaseContext

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getBaseContext());
NotificationCompat.Builder mBuilder =new NotificationCompat.Builder(this.context)
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getBaseContext());