3

Trying to use DateTime in an Android app (API 15) but get the following in logcat:

E/dalvikvm(794): Unable to resolve Lorg/joda/time/base/AbstractInstant; annotation class 1383
D/AndroidRuntime(794): Shutting down VM
W/dalvikvm(794): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
E/AndroidRuntime(794): FATAL EXCEPTION: main
E/AndroidRuntime(794): java.lang.NoClassDefFoundError: org/joda/convert/ToString
E/AndroidRuntime(794):  at java.lang.reflect.Method.getDeclaredAnnotations(Native Method)
E/AndroidRuntime(794):  at java.lang.reflect.Method.getDeclaredAnnotations(Method.java:267)
E/AndroidRuntime(794):  at com.fasterxml.jackson.databind.introspect.AnnotatedClass._addMixUnders(AnnotatedClass.java:999)
....

I have a /libs directory and it has joda-time-2.1.jar. Am I missing something obvious?


I should have looked more carefully at the error stack - in particular the line: java.lang.NoClassDefFoundError: org/joda/convert/ToString

That is from the jar joda-convert, not joda-time and the joda-convert jar file was NOT in my libs directory.

Note: There doesn't seem to be any need to explicitly export the jar

casperOne
  • 73,706
  • 19
  • 184
  • 253
Richard Berger
  • 247
  • 2
  • 11
  • Are you exported the jar file to your application..??? – user4232 Dec 03 '12 at 06:28
  • Yes, I tried that without any success - same exact error. (Also http://stackoverflow.com/questions/10437438/android-java-lang-noclassdeffounderror-using-joda-libraries seems to indicate it isn't necessary). Would be happy to do the export, if it only worked. – Richard Berger Dec 03 '12 at 14:43

2 Answers2

4

You need to add the joda-convert.jar to your libs folder. Download the jar from http://sourceforge.net/projects/joda-convert/files/joda-convert/

Catalin Morosan
  • 7,897
  • 11
  • 53
  • 73
  • Thanks - I had added an answer along these lines, but it was deleted. I will accept your answer as someone might as well get credit. – Richard Berger Jan 14 '13 at 16:44
  • 1
    Can anyone clarify why you have to do this in order to use Joda Time on Android, but it doesn't need to be done in order to use it in plain Java? – Jules Feb 13 '14 at 07:18
1

You should use joda-time-android. This is jodatime library adapted for android.

Eugene Smykov
  • 450
  • 2
  • 4
  • 12