Java(Android) - 类找不到异常 [英] Java (Android) - class not found exception
问题描述
- 下载包从这里,并在本地解压缩。
- 在Eclipse中,要添加这个新库, strong>(Window>)首选项> Java>构建路径>用户库,单击新建,将其命名为
apache-commons-net
,然后通过选择下载中的 .jar 文件添加JAR ... 。 - 对于每个 .jar ,我将源附件中添加为这里描述。
- 一旦完成,我右键单击我的项目并选择属性> Java构建路径>库,单击添加库...>用户库>(下一步>)选择
apache-commons-net
>完成。图书馆随后在库标签中与Android 2.2
一起显示。
我开始编程,代码完成对于类/方法/等很好。从这个图书馆。包括进口报表等等。一切似乎都应该正常工作。问题是,当我运行应用程序,它强制关闭,我的LogCat在Eclipse中显示以下错误:
找不到类' org.apache.commons.net.ftp.FTPClient',从方法引用< ...>
...
引起的:java.lang.NoClassDefFoundError: org.apache.commons.net.ftp.FTPClient
看起来我已经把所有东西都正确设置了,所以为什么执行抱怨说找不到班级?
非常感谢任何想法或帮助。
- Ian
您需要复制jar到项目中的 libs
目录。 ADK从该文件夹中选择库,并将其转换为针对Dalvik优化的类。
编辑
在此问题中提供更多信息:将外部.jar文件导入Android项目
I'm trying to do some simple FTP stuff in Android. After researching a little bit, I decided to go with the apache-commons-net. Here are the steps I took to get it working under Eclipse.
- Downloaded the package from here and unpacked it locally.
- In Eclipse, to add this new library, I go to (Window >) Preferences > Java > Build Path > User Libraries, click New, name it
apache-commons-net
, then Add JARs... to it by picking the .jar files that came in the download. - For each .jar, I add in the Source attachment as described here.
- Once this is done, I right-click my project and choose Properties > Java Build Path > Libraries, click Add Library... > User Library > (Next >) choose
apache-commons-net
> Finish. The library then shows up alongsideAndroid 2.2
in the Libraries tab.
I start programming, and code completion works fine for the classes/methods/etc. from this library. Import statements are included, etc. Everything seems to work as it should. The problem is, when I run the app, it force closes and my LogCat in Eclipse shows the following error:
Could not find class 'org.apache.commons.net.ftp.FTPClient', referenced from method <...>
...
Caused by: java.lang.NoClassDefFoundError: org.apache.commons.net.ftp.FTPClient
It seems like I've set everything up correctly, so why is the execution complaining that it can't find the class???
Any ideas or help is greatly appreciated.
- Ian
You need to copy the jar(s) to the libs
directory in the project. The ADK picks the libraries from that folder and convert them into classes optimized for Dalvik.
Edit
There might be some more information in this question: Importing external .jar file to Android project
这篇关于Java(Android) - 类找不到异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!