I am running my application on emulator with Android 2.2 and API level 8.

I have tested the following 2 lines in my code:

 long diffInDays = TimeUnit.MILLISECONDS.toDays(diffInMs); // API Level 9
 long diffInDays = TimeUnit.DAYS.convert(diffInMs,TimeUnit.MILLISECONDS); // API Level 1

I am using line above to convert time in Milliseconds to time in days but i get the following exception. Why?

09-05 06:34:43.183: W/dalvikvm(12995): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
09-05 06:34:43.222: E/AndroidRuntime(12995): FATAL EXCEPTION: main
09-05 06:34:43.222: E/AndroidRuntime(12995): java.lang.NoSuchFieldError: java.util.concurrent.TimeUnit.DAYS
09-05 06:34:43.222: E/AndroidRuntime(12995):    at org.mabna.order.businessLayer.db.BoSaleDocuments.getEntAcc002Collection(BoSaleDocuments.java:161)
09-05 06:34:43.222: E/AndroidRuntime(12995):    at org.mabna.order.ui.ActReportAcc002.onCreate(ActReportAcc002.java:178)
09-05 06:34:43.222: E/AndroidRuntime(12995):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-05 06:34:43.222: E/AndroidRuntime(12995):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-05 06:34:43.222: E/AndroidRuntime(12995):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-05 06:34:43.222: E/AndroidRuntime(12995):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-05 06:34:43.222: E/AndroidRuntime(12995):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-05 06:34:43.222: E/AndroidRuntime(12995):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-05 06:34:43.222: E/AndroidRuntime(12995):    at android.os.Looper.loop(Looper.java:123)
09-05 06:34:43.222: E/AndroidRuntime(12995):    at android.app.ActivityThread.main(ActivityThread.java:4627)
09-05 06:34:43.222: E/AndroidRuntime(12995):    at java.lang.reflect.Method.invokeNative(Native Method)
09-05 06:34:43.222: E/AndroidRuntime(12995):    at java.lang.reflect.Method.invoke(Method.java:521)
09-05 06:34:43.222: E/AndroidRuntime(12995):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-05 06:34:43.222: E/AndroidRuntime(12995):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-05 06:34:43.222: E/AndroidRuntime(12995):    at dalvik.system.NativeStart.main(Native Method)
有帮助吗?

解决方案

toDays(long duration) require API level 9.

see http://developer.android.com/reference/java/util/concurrent/TimeUnit.html

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top