NoClassDefFound在NotificationCompat.Builder [英] NoClassDefFound in NotificationCompat.Builder

查看:122
本文介绍了NoClassDefFound在NotificationCompat.Builder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的概念是在特定的时间,以得到通知。很显然,我做到了,直到我包括超过蜂窝和它上面更低版本的支持。

我已经设置分SDK版本8和目标SDK 17.作为类编码大得多,我表示在这个问题只存在于核心区:

  INT currentapiVersion = android.os.Build.VERSION.SDK_INT;
        通知通知;
        的PendingIntent contentIntent = PendingIntent.getActivity(这一点,0,
                新的意图(这一点,TaskDetails.class),0);        如果(currentapiVersion< android.os.Build.VERSION_ codeS.HONEYCOMB){            通知=新的通知(图标,文字,时间);
            notification.setLatestEventInfo(这一点,标题,正文,contentIntent);
            notification.flags | = Notification.FLAG_AUTO_CANCEL;
            mNM.notify(通知,通知);
        }其他{
            NotificationCompat.Builder建设者=新NotificationCompat.Builder(
                    本);
            通知= builder.setContentIntent(co​​ntentIntent)
                    .setSmallIcon(图标).setTicker(文本).setWhen(时间)
                    .setAutoCancel(真).setContentTitle(职称)
                    .setContentText(文本).build();            mNM.notify(通知,通知);
        }

的问题在于,


  • 通知类的一些方法和构造是德precated。

  • 那么,选择这一点,developer.android.com建议使用
    Notification.Builder

  • 但是,类 Notification.Builder 已被列入的方法
    在API级别11(因而在系表现出错误呼叫需要API级别11个或多个)。

  • 所以,它没有让我运行的项目。

  • 更google搜索后,给了我使用类解决方案
    NotificationCompat.Builder

最后,到达了没有发现错误的阶段,我跑我的项目在我的索尼Xperia TIPO双ST21i2 ...

悲惨的结局:我收到以下错误日志:

  6月6日至一日:34:14.199:E / AndroidRuntime(4178):致命异常:主要
6月6日至一日:34:14.199:E / AndroidRuntime(4178):java.lang.NoClassDefFoundError的:android.support.v4.app.NotificationCompat $生成器
6月6日至一日:34:14.199:E / AndroidRuntime(4178):在com.todotaskmanager.service.NotifyService.showNotification(NotifyService.java:99)
6月6日至一日:34:14.199:E / AndroidRuntime(4178):在com.todotaskmanager.service.NotifyService.onStartCommand(NotifyService.java:68)
6月6日至一日:34:14.199:E / AndroidRuntime(4178):在android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2359)
6月6日至一日:34:14.199:E / AndroidRuntime(4178):在android.app.ActivityThread.access $ 1900年(ActivityThread.java:123)
6月6日至一日:34:14.199:E / AndroidRuntime(4178):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1210)
6月6日至一日:34:14.199:E / AndroidRuntime(4178):在android.os.Handler.dispatchMessage(Handler.java:99)
6月6日至一日:34:14.199:E / AndroidRuntime(4178):在android.os.Looper.loop(Looper.java:137)
6月6日至一日:34:14.199:E / AndroidRuntime(4178):在android.app.ActivityThread.main(ActivityThread.java:4424)
6月6日至一日:34:14.199:E / AndroidRuntime(4178):在java.lang.reflect.Method.invokeNative(本机方法)
6月6日至一日:34:14.199:E / AndroidRuntime(4178):在java.lang.reflect.Method.invoke(Method.java:511)
6月6日至一日:34:14.199:E / AndroidRuntime(4178):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:817)
6月6日至一日:34:14.199:E / AndroidRuntime(4178):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
6月6日至一日:34:14.199:E / AndroidRuntime(4178):在dalvik.system.NativeStart.main(本机方法)


解决方案

好吧...我解决我的问题。

右键点击您的项目转到属性 - > Java构建路径。选择订单的出口标签。确保Android的私家藏书被选中。如果您引用的库项目。做库项目也同样如此。清理并生成。

此外转到Android SDK中的经理,并检查是否有Android SDK中建安装的工具。这可能不是必要的,但要确保你有安装的Andr​​oid构建工具。

The concept is to get notification at a specific time. Obviously, I did it, until I included the support for versions lower than HoneyComb and above it.

I have set min SDK version 8 and target SDK 17. As the class coding is much bigger, I am showing only the core area where the problem exists:

int currentapiVersion = android.os.Build.VERSION.SDK_INT;
        Notification notification;
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, TaskDetails.class), 0);

        if (currentapiVersion < android.os.Build.VERSION_CODES.HONEYCOMB) {

            notification = new Notification(icon, text, time);
            notification.setLatestEventInfo(this, title, text, contentIntent);
            notification.flags |= Notification.FLAG_AUTO_CANCEL;
            mNM.notify(NOTIFICATION, notification);
        } else {
            NotificationCompat.Builder builder = new NotificationCompat.Builder(
                    this);
            notification = builder.setContentIntent(contentIntent)
                    .setSmallIcon(icon).setTicker(text).setWhen(time)
                    .setAutoCancel(true).setContentTitle(title)
                    .setContentText(text).build();

            mNM.notify(NOTIFICATION, notification);
        }

The problem is that,

  • Some methods and constructors of Notifications class are deprecated.
  • So, alternative to this, "developer.android.com" suggested to use Notification.Builder.
  • But, the class Notification.Builder has methods that were included in API level 11 (and thus showed errors in the lines "Call requires API level 11 or more").
  • So, it didn't allow me to run the project.
  • After more googling, gave me the solution to use class NotificationCompat.Builder.

Finally, reached the stage where no errors were found, and I ran my project on my Sony Xperia Tipo Dual ST21i2...

Tragic ending: I get the following error log:

06-01 06:34:14.199: E/AndroidRuntime(4178): FATAL EXCEPTION: main
06-01 06:34:14.199: E/AndroidRuntime(4178): java.lang.NoClassDefFoundError: android.support.v4.app.NotificationCompat$Builder
06-01 06:34:14.199: E/AndroidRuntime(4178):     at com.todotaskmanager.service.NotifyService.showNotification(NotifyService.java:99)
06-01 06:34:14.199: E/AndroidRuntime(4178):     at com.todotaskmanager.service.NotifyService.onStartCommand(NotifyService.java:68)
06-01 06:34:14.199: E/AndroidRuntime(4178):     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2359)
06-01 06:34:14.199: E/AndroidRuntime(4178):     at android.app.ActivityThread.access$1900(ActivityThread.java:123)
06-01 06:34:14.199: E/AndroidRuntime(4178):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
06-01 06:34:14.199: E/AndroidRuntime(4178):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-01 06:34:14.199: E/AndroidRuntime(4178):     at android.os.Looper.loop(Looper.java:137)
06-01 06:34:14.199: E/AndroidRuntime(4178):     at android.app.ActivityThread.main(ActivityThread.java:4424)
06-01 06:34:14.199: E/AndroidRuntime(4178):     at java.lang.reflect.Method.invokeNative(Native Method)
06-01 06:34:14.199: E/AndroidRuntime(4178):     at java.lang.reflect.Method.invoke(Method.java:511)
06-01 06:34:14.199: E/AndroidRuntime(4178):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
06-01 06:34:14.199: E/AndroidRuntime(4178):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
06-01 06:34:14.199: E/AndroidRuntime(4178):     at dalvik.system.NativeStart.main(Native Method)

解决方案

Okay... i solved my problem.

Right click on your project goto properties -> Java Build Path. Choose Order export tab. Make sure that Android Private Libraries is selected. If you have referenced library project. do the same for the library project also. Clean and Build.

Also goto android sdk manager and check that you have the android sdk build tools installed. This may not be necessary but make sure you have android build tools installed.

这篇关于NoClassDefFound在NotificationCompat.Builder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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