5

I'm stuck from about 2 hours on a problem that i thought it was easy to solve. I'm building a custom date-time picker for the android platform and, because of the slowness of the standard java.util.Calendar and java.util.Date classes, i decided to use the JODA library.

Unfortunately i've got no experience with 'JAR' references (forgive me...i come from COM and .NET assemblies world =)...), but i learn some tips on internet but obviously they seems to be wrong... These are the steps i took to use the library in my project:

  1. Download the latest JODA library 2.1
  2. Create the 'lib' folder into my project folder
  3. Add 'joda-time-2.1.jar' to the 'lib' folder.
  4. Add the 'joda-time-2.1.jar' library to the build path.
  5. Add 'joda-time-2.1-javadoc.jar' and 'joda-time-2.1-sources.jar' to the 'lib' folder
  6. Set the above libraries as 'java source attachements' and 'javadoc location' for the joda-time-2.1 referenced library.
  7. Use the new library into my code (the ehm ehm 'intelli-sense' and compiler don't throws any error or warning)
  8. Start debug on real or virtual device.

When it comes to the following line (the first one that uses JODA BTW), debug stops:

DateTime newDate = new DateTime(2012, 5, 3, 12, 0, 0);

And returns the following stack trace:

05-03 19:09:14.349: E/AndroidRuntime(4071): java.lang.NoClassDefFoundError: org.joda.time.DateTime
05-03 19:09:14.349: E/AndroidRuntime(4071):     at it.paganel.droidMessageExport.Control.TimePickerControl.SetTimePart(TimePickerControl.java:83)
05-03 19:09:14.349: E/AndroidRuntime(4071):     at it.paganel.droidMessageExport.Control.TimePickerControl.onClick(TimePickerControl.java:116)
05-03 19:09:14.349: E/AndroidRuntime(4071):     at android.view.View.performClick(View.java:2454)
05-03 19:09:14.349: E/AndroidRuntime(4071):     at android.view.View$PerformClick.run(View.java:9030)
05-03 19:09:14.349: E/AndroidRuntime(4071):     at android.os.Handler.handleCallback(Handler.java:587)
05-03 19:09:14.349: E/AndroidRuntime(4071):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-03 19:09:14.349: E/AndroidRuntime(4071):     at android.os.Looper.loop(Looper.java:123)
05-03 19:09:14.349: E/AndroidRuntime(4071):     at android.app.ActivityThread.main(ActivityThread.java:4641)
05-03 19:09:14.349: E/AndroidRuntime(4071):     at java.lang.reflect.Method.invokeNative(Native Method)
05-03 19:09:14.349: E/AndroidRuntime(4071):     at java.lang.reflect.Method.invoke(Method.java:521)
05-03 19:09:14.349: E/AndroidRuntime(4071):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:870)
05-03 19:09:14.349: E/AndroidRuntime(4071):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
05-03 19:09:14.349: E/AndroidRuntime(4071):     at dalvik.system.NativeStart.main(Native Method)
05-03 19:09:14.349: E/AndroidRuntime(4071): Caused by: java.lang.ClassNotFoundException: org.joda.time.DateTime in loader dalvik.system.PathClassLoader[/data/app/it.paganel.droidMessageExport-2.apk]
05-03 19:09:14.349: E/AndroidRuntime(4071):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
05-03 19:09:14.349: E/AndroidRuntime(4071):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
05-03 19:09:14.349: E/AndroidRuntime(4071):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
05-03 19:09:14.349: E/AndroidRuntime(4071):     ... 13 more

Someone can help me? Thanks in advance!

GiveEmTheBoot
  • 534
  • 9
  • 24
  • What is the import statement that you use for DateTime? – Sam May 03 '12 at 18:54
  • I've been having same problem having opened my project on a different computer, Eclipse compiles against the library ok but it crashes at the first call to the JodaTime library DateTime constructor. – Luke May 03 '12 at 19:13

2 Answers2

7

Rename the lib folder to libs. As of ADT Tools 17 externals jars get only packaged into the apk if they are inside this folder. Alternatively you could go to "configure build path.."->"Order and Export" and click the checkbox next to the jar.

Renard
  • 6,909
  • 2
  • 27
  • 23
  • Yes i've got it! I wrong the folder name...renaming it "libs" instead of "lib" it works very well!! but i noticed a big slowness when i use DateTime() constructor. For example, to create a new DateTime object my Samsung Omnia 2 with O2Droid porting (based on Froyo release), takes about 30 seconds. My Acer A500 tablet with Honeycomb, takes about 3 seconds...is it normal??? can this issue be related to the method i use to reference a JAR? anyone knows some trick to speed up performance with this library? – GiveEmTheBoot May 05 '12 at 10:46
  • You might want to check this discussion for help with the slow startup: http://stackoverflow.com/questions/5059663/android-java-joda-date-is-slow – sdouglass Mar 19 '14 at 22:15
1

For others who might be looking for a solution, there is another possible cause which I just discovered: Open Project>Properties>Java Build Path>Libraries and check if JodaTime is under Android Dependencies or Android Private Libraries. Then make sure that the corresponding option is checked on the Order and Export tab. I had to check Android Private Libraries (where JodaTime was listed) in order to make it work.

I assume this applies to similar issues, too, and is not necessarily related to JodaTime.

Michael Jess
  • 1,907
  • 1
  • 19
  • 17