我正在使用Android 2.2和API级别8在模拟器上运行我的应用程序。
我在代码中测试了以下两行:
long diffInDays = TimeUnit.MILLISECONDS.toDays(diffInMs); // API Level 9
long diffInDays = TimeUnit.DAYS.convert(diffInMs,TimeUnit.MILLISECONDS); // API Level 1
我使用上面的行以毫秒为单位将时间转换为时间,但是我得到以下异常。为什么呢?
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)
答案 0 :(得分:5)
toDays(long duration)
需要API级别9.
请参阅http://developer.android.com/reference/java/util/concurrent/TimeUnit.html