问题描述
我建立一个使用时间的应用程序。我决定使用乔达时间。我想乔达时间添加到我的应用程序。我有添加的.jar
文件到库没有经验。我跟着these步骤(参见下图),我这样想着。我的项目是显示没有错误,但是当我运行一个简单的测试: DateTime的测试=新的日期时间();
我得到一个强制关闭,并出现以下错误:
找不到类的org.joda.time.DateTime,从法XXXX引用
java.lang.NoClassDefFoundError的:org.joda.time.DateTime
这是我遵循的步骤:
- 创建在Eclipse中的Android项目。
- 在下载乔达时间
- 在Eclipse中寻找你的项目在包资源管理器,右键单击它,然后把它叫做
新建 - >文件夹 - >库
。 注意:我没有这样做,因为我已经有一个文件夹命名为库
- 复制(或)拖动和放大器;删除
乔达时间,2.1.jar
到新创建库
文件夹。 - 右键再次单击您的项目(在包资源管理器),那么
属性 - > Java构建路径 - >图书馆 - >添加罐 - >乔达时间,2.1.jar
。
现在你可以用这个code测试:
DateTime的测试=新的日期时间();
导入后:
进口org.joda.time.DateTime;
由于它是一个Android项目,只是引用乔达jar文件是不行的。你需要捆绑的jar文件以及您的APK,可以这样做: -
-
属性 - > Java构建路径 - >在线订单和放大器;导出
-
请检查
乔达时间 - * - *瓶
并点击确定。就大功告成了。
说明:引用的jar单独将不仅解决了编制问题在Eclipse(或任何其他IDE),但是当 APK 的创建乔达时间 JAR文件将无法导出/你的APK捆绑一起。这就是为什么它抛出的的NoClassDefFoundError
但是,当您检查乔达时间罐子的订购与放大器;导出的,它会确保罐子也被捆绑在/一起时,它会创建你的APK。
I am building an app that uses time. I decided to use Joda time. I am trying to add joda time to my app. I have no experience with adding .jar
files to the libs. I followed these steps(see bottom), or so I thought. My project is showing no errors, but when I run a simple test: DateTime test = new DateTime();
I get a force close and the following error:
Could not find class 'org.joda.time.DateTime', referenced from method xxxx
java.lang.NoClassDefFoundError: org.joda.time.DateTime
These are the steps I followed:
- Create your android project in eclipse.
- Download Joda Time
- In Eclipse look for your project at package explorer and right click on it then call it
New -> Folder -> libs
. Note: I did not do this because I already had a folder namedlibs
- Copy (or) drag & drop the
joda-time-2.1.jar
into the newly createdlibs
folder. - Right click on your project again (in package explorer) then
Properties -> Java Build Path -> Libraries -> Add Jars -> joda-time-2.1.jar
.
Now you can test with this code :
DateTime test = new DateTime();
After importing:
import org.joda.time.DateTime;
Since it is an Android project, just referencing the Joda jar file won't do. You'll need to bundle that jar file along with your apk which can be done like this:-
Properties -> Java Build Path -> Order & Export
Check on the
joda-time-*-*.jar
and click Ok. You're done.
Explanation: Referencing the jar alone will only solve the compilation issues in Eclipse (or any other IDE), but when the apk is created the "joda-time" jar file won't be exported/bundled along with your "apk". That is the reason why it throws the NoClassDefFoundError.
But when you check the joda-time jar in Order & Export, it'll make sure that the jar is also bundled inside/along with your "apk" whenever it is created.
这篇关于添加乔达时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!