I subclassed a TimerTask to periodically capture an image and some sensor data to upload to an AppEngine server. The application works perfectly on the emulator but when loaded on phone (2.2.1) and task is scheduled with Timer, I get the following error:
11-18 19:32:45.810: E/AndroidRuntime(685): FATAL EXCEPTION: main
11-18 19:32:45.810: E/AndroidRuntime(685): java.lang.IllegalArgumentException
11-18 19:32:45.810: E/AndroidRuntime(685): at java.util.Timer.schedule(Timer.java:483)
11-18 19:32:45.810: E/AndroidRuntime(685): at com.ms.revolver.CaptureActivity$3.onClick(CaptureActivity.java:77)
11-18 19:32:45.810: E/AndroidRuntime(685): at android.view.View.performClick(View.java:2449)
11-18 19:32:45.810: E/AndroidRuntime(685): at android.widget.CompoundButton.performClick(CompoundButton.java:99)
11-18 19:32:45.810: E/AndroidRuntime(685): at android.view.View$PerformClick.run(View.java:9027)
11-18 19:32:45.810: E/AndroidRuntime(685): at android.os.Handler.handleCallback(Handler.java:587)
11-18 19:32:45.810: E/AndroidRuntime(685): at android.os.Handler.dispatchMessage(Handler.java:92)
11-18 19:32:45.810: E/AndroidRuntime(685): at android.os.Looper.loop(Looper.java:123)
11-18 19:32:45.810: E/AndroidRuntime(685): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-18 19:32:45.810: E/AndroidRuntime(685): at java.lang.reflect.Method.invokeNative(Native Method)
11-18 19:32:45.810: E/AndroidRuntime(685): at java.lang.reflect.Method.invoke(Method.java:521)
11-18 19:32:45.810: E/AndroidRuntime(685): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-18 19:32:45.810: E/AndroidRuntime(685): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-18 19:32:45.810: E/AndroidRuntime(685): at dalvik.system.NativeStart.main(Native Method)
Not sure why it works on emulator but not on phone; any ideas?
It is giving you this error because the time you scheduled is negative. From the docs
Try debugging it to make sure you don’t come up with a negative value.