2
我有以下简单的类,我想用来通知用户传入的消息(我将随着应用程序的发展而演变)。但现在,在最后一行,则下面的错误,我不能运行:NotificationCompat.Builder:无法解析方法构建()
无法解析方法构建()
这里是代码:
import android.app.Activity;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
public class UserNotificationActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void triggerNoti() {
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("My notification")
.setContentText("Hello World!");
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(001, mBuilder.build());
}
}
我试过这个solution但没有做任何改变
我在做什么错了?
P.S.:目标(&分钟)SDK = 21
感谢您的解决方案,但遗憾的是并没有完全解决我的困境尚未我有同样的错误!同样的错误出现在您的最后一行 –
检查您的导入:import android.support.v4.app.NotificationCompat; – ADM
它已经导入.. –