简体   繁体   English

Android NoClassDefFoundError NotificationCompat.Builder

[英]Android NoClassDefFoundError NotificationCompat.Builder

java.lang.NoClassDefFoundError: android/support/v4/app/NotificationCompat$Builder

I know this error is resolved by adding private libraries to project, but in my case if I add private libraries then I am getting different error: 我知道可以通过将私有库添加到项目中来解决此错误,但是在我的情况下,如果我添加私有库,则会收到不同的错误:

Unable to execute dex: Multiple dex files define

And the fix for above was removing private libraries which I found here 上面的解决方法是删除我在这里找到的私有库

So any better solution??? 有什么更好的解决方案吗???

My code: 我的代码:

private void check() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(
            getApplicationContext());
    Notification notification = builder.setSmallIcon(R.drawable.icon)
            .setContentTitle("New notification")
            .setContentText("Hello world!").build();
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(1, notification);
}

My project build path : 我的项目构建路径:

在此处输入图片说明

I think you have added two similar libraries to your project . 我认为您已经在项目中添加了两个类似的库。 Go to project properties ->java Build Path->libraries 转到项目属性-> Java构建路径->库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM