Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoClassDefFound in NotificationCompat.Builder

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)
like image 753
Chintan Soni Avatar asked Jun 01 '13 01:06

Chintan Soni


1 Answers

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.

like image 186
Chintan Soni Avatar answered Nov 09 '22 04:11

Chintan Soni