java.lang.NoSuchMethodError:android.app.Notification $ Builder.build [英] java.lang.NoSuchMethodError: android.app.Notification$Builder.build

查看:766
本文介绍了java.lang.NoSuchMethodError:android.app.Notification $ Builder.build的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have just added notification icon to the notification bar in my app, which supports Android >= 11 and it started to throw below error:

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)

下面是我的code的一部分,负责建设的通知。

Below is my part of code responsible for building notification.

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();

有没有人有,为什么我得到的NoSuchMethodError简单.build方法的任何想法?还是我失去了一些东西在这里?

Does anyone have any idea why I'm getting NoSuchMethodError for simple .build method? Or am I just missing something here?

先谢谢了。

更新
看来,我认为.build方法已在API16,愚蠢的问题增加了,但也许这将帮助别人:)

UPDATE It appeared to me that .build method has been added in API16, stupid question, but maybe it will help someone :)

推荐答案

答案是一样的,如下:<一href=\"http://stackoverflow.com/questions/16523807/java-lang-nosuchmethoderror-android-app-notificationbuilder-addaction\">java.lang.NoSuchMethodError: android.app.Notification $ Builder.addAction

The answer is just the same as here: java.lang.NoSuchMethodError: android.app.Notification$Builder.addAction

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

You can use NotificationCompat.Builder from the Android Support package (android.support.v4.app.NotificationCompat.Builder).

这篇关于java.lang.NoSuchMethodError:android.app.Notification $ Builder.build的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆