Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call requires API level 24(current minimum is 12):android.icu.util.calendar

I am making a simple alarm app. Wherever I am using Calendar class it's showing an error same as title.

Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 10);
calendar.set(Calendar.MINUTE, 30);

Whenever I build my project, it builds fine but app crashes when it's launched on phone. Below is the Logcat:

07-22 18:24:15.607 18047-18047/com.example.panwa.afinal D/AndroidRuntime: Shutting down VM
07-22 18:24:15.607 18047-18047/com.example.panwa.afinal W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x40d952d0)
07-22 18:24:15.627 18047-18047/com.example.panwa.afinal E/AndroidRuntime: ***FATAL EXCEPTION: main
  java.lang.NoClassDefFoundError: android.icu.util.Calendar***
      at com.example.panwa.afinal.MainActivity.startAt10(MainActivity.java:70)
      at com.example.panwa.afinal.MainActivity$3.onClick(MainActivity.java:46)
      at android.view.View.performClick(View.java:4275)
      at android.view.View$PerformClick.run(View.java:17434)
      at android.os.Handler.handleCallback(Handler.java:615)
      at android.os.Handler.dispatchMessage(Handler.java:92)
      at android.os.Looper.loop(Looper.java:177)
      at android.app.ActivityThread.main(ActivityThread.java:4947)
      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:1038)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
      at dalvik.system.NativeStart.main(Native Method)
07-22 18:25:33.824 18047-18047/com.example.panwa.afinal I/Process: Sending signal. PID: 18047 SIG: 9

I have a set my min SDK to be 11 but still it's not working.

like image 591
Shivam Panwar Avatar asked Jul 23 '16 03:07

Shivam Panwar


1 Answers

Instead of importing android.icu.util.calendar, try importing java.util.Calendar.

The android.icu.util.calendar is the ICU replacement for java.util.Calendar but it's only available starting from API 24. So, it will only work on the devices which is API 24 and above.

Ref :

  • Java Calendar
  • ICU Calendar
like image 69
Ye Lin Aung Avatar answered Sep 17 '22 20:09

Ye Lin Aung