eclipse Java (Android) - 找不到类异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6974670/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 16:47:09  来源:igfitidea点击:

Java (Android) - class not found exception

javaandroideclipseinstallation

提问by istrasci

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.

我正在尝试在 Android 中执行一些简单的 FTP 操作。经过一番研究,我决定使用apache-commons-net。以下是我为使其在 Eclipse 下工作所采取的步骤。

  1. Downloaded the package from hereand unpacked it locally.
  2. 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 .jarfiles that came in the download.
  3. For each .jar, I add in the Source attachmentas described here.
  4. 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 alongside Android 2.2in the Librariestab.
  1. 从这里下载包并在本地解压。
  2. 在 Eclipse 中,要添加这个新库,我转到(Window >) Preferences > Java > Build Path > User Libraries,单击New,命名它apache-commons-net,然后通过选择进来的.jar文件向它添加 JARs...下载。
  3. 对于每个.jar,我添加了源附件如here所述。
  4. 完成后,我右键单击我的项目并选择Properties > Java Build Path > Libraries,单击Add Library... > User Library > (Next >) 选择apache-commons-net> Finish。该库随后会显示Android 2.2在“库”选项卡中。

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:

我开始编程,代码完成对类/方法/等工作正常。从这个图书馆。包括导入语句等。一切似乎都正常工作。问题是,当我运行应用程序时,它强制关闭并且我在 Eclipse 中的 LogCat 显示以下错误:

Could not find class 'org.apache.commons.net.ftp.FTPClient', referenced from method <...>
...
Caused by: java.lang.NoClassDefFoundError: org.apache.commons.net.ftp.FTPClient

找不到类 'org.apache.commons.net.ftp.FTPClient',从方法 <...> 引用
...
引起: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
  • 伊恩

回答by Augusto

You need to copy the jar(s) to the libsdirectory in the project. The ADK picks the libraries from that folder and convert them into classes optimized for Dalvik.

您需要将 jar(s) 复制到libs项目中的目录。ADK 从该文件夹中选取库并将它们转换为针对 Dalvik 优化的类。

Edit

编辑

There might be some more information in this question: Importing external .jar file to Android project

这个问题可能有更多信息:Importing external .jar file to Android project