添加乔达时间时间

2023-09-05 10:11:52 作者:临岸端红烛"

我建立一个使用时间的应用程序。我决定使用乔达时间。我想乔达时间添加到我的应用程序。我有添加的.jar 文件到库没有经验。我跟着these步骤(参见下图),我这样想着。我的项目是显示没有错误,但是当我运行一个简单的测试: DateTime的测试=新的日期时间(); 我得到一个强制关闭,并出现以下错误:

 找不到类的org.joda.time.DateTime,从法XXXX引用
 java.lang.NoClassDefFoundError的:org.joda.time.DateTime
 

这是我遵循的步骤:

创建在Eclipse中的Andr​​oid项目。 在下载乔达时间 在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 named libs Copy (or) drag & drop the joda-time-2.1.jar into the newly created libs 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.