Java PendingEvent()在PendingEvent中不是公共的;无法从包外部访问
我知道有人问过这类问题,但他们无法解决我的问题,因此我再次问,因为我的问题得到了准确的解决,我使用android studio 3.0.1创建简单的通知应用程序,当我运行此应用程序时,它会显示错误,如下所示: 错误:(40,25)错误:PendingEvent()在PendingEvent中不是公共的;无法从包外部访问 我的MainActivity.java如下Java PendingEvent()在PendingEvent中不是公共的;无法从包外部访问,java,android,android-pendingintent,Java,Android,Android Pendingintent,我知道有人问过这类问题,但他们无法解决我的问题,因此我再次问,因为我的问题得到了准确的解决,我使用android studio 3.0.1创建简单的通知应用程序,当我运行此应用程序时,它会显示错误,如下所示: 错误:(40,25)错误:PendingEvent()在PendingEvent中不是公共的;无法从包外部访问 我的MainActivity.java如下 package com.example.ram.notification; import android.app.Notificat
package com.example.ram.notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
NotificationCompat.Builder notification;
private static final int uniqueID = 45612;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
notification = new NotificationCompat.Builder(this);
notification.setAutoCancel(true);
}
public void ClickNotification(View view){
//build the notification
notification.setSmallIcon(R.drawable.myimage);
notification.setTicker("this is the ticker");
notification.setWhen(System.currentTimeMillis());
notification.setContentTitle("Here is the title");
notification.setContentText("I am the body of your notificattion");
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = new PendingIntent().getActivity(this, 0,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setContentIntent(pendingIntent);
//build notification and issues it
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(uniqueID, notification.build());
}
}
请帮助我该怎么办?只需删除40行中的“new”关键字即可 一定是
pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
“请帮帮我,我该怎么办?”=>!它清楚地描述了如何创建实例。可能重复的,那么我应该怎么做??“那么我应该怎么做?”,再次问这个问题?上面的两条评论已经回答了这个问题,但您选择忽略它,所以让我更清楚地说:阅读。这个手动。同时拆下支架
()
。您正在调用静态函数,因此不需要首先创建实例。