java.lang.NoSuchMethodError:android.app.Notification $ Builder.build

我刚刚添加通知图标到我的应用程序的通知栏,它支持Android> = 11,并开始抛出以下错误:

java.lang.NoSuchMethodError: android.app.Notification$Builder.build at com.xynapse.autokam.MainActivity.onCreate(MainActivity.java:195) at android.app.Activity.performCreate(Activity.java:4519) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) at android.app.ActivityThread.access$600(ActivityThread.java:123) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4464) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:822) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:589) at dalvik.system.NativeStart.main(Native Method) 

以下是我负责构build通知的代码的一部分。

 navigationIntent = new Intent(this, MainActivity.class); navigationIntent.setAction(Intent.ACTION_MAIN); navigationIntent.addCategory(Intent.CATEGORY_LAUNCHER); navigationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP); pi = PendingIntent.getActivity(this, 0, navigationIntent,0); notification = new Notification.Builder(this) .setContentIntent(pi) .setSmallIcon(R.drawable.splash_logo) .setContentTitle("Status") .setContentText("Standby mode") .build(); 

有没有人有任何想法,为什么我得到简单的.build方法NoSuchMethodError? 还是我在这里错过了什么?

提前致谢。

更新在我看来,.build方法已被添加到API16,愚蠢的问题,但也许它会帮助别人:)

答案和这里一样: java.lang.NoSuchMethodError:android.app.Notification $ Builder.addAction

您可以使用Android支持包( android.support.v4.app.NotificationCompat.Builder )中的NotificationCompat.Builder