您的位置:首页 > 理论基础 > 计算机网络

NoClassDefFoundError: org.apache.http.entity.mime.content.StringBody

2014-09-26 11:24 567 查看
1.出错代码:StringBody strbType = new StringBody("123" , Charset.forName("UTF-8"));

2.问题描述:编译期间没问题,运行后报异常“NoClassDefFoundError: org.apache.http.entity.mime.content.StringBody”

3.问题原因1:如下图,libs1中的包编译时都OK,但该Android项目生成apk时,都没有被编进.dex,所以运行时缺失(原因后面说)。



解决方法A:全部放进libs中后,问题解决;

解决方法B:右键上述3.中libs1目录,点击build path--> use as source folder 即可;

解决方法C:点击面板“Order and Export”,勾选要导出的“entries”,选中下图红框中的jar包即可(所以,生成apk时丢掉的原因是这里要选中最后导出的"entry");



4.问题原因2:没有正确引用外部android工程。



解决方法:引用的外部工程应从上图的" Required projects "改为下图的" Library project "方式;



补充说明:至于Library project的概念,提供以下引文供参考

the components, code and resources of the <span style="color:#ff0000;">library project </span>are compiled and packaged into the .apk file of the compiled application.

An Android<span style="color:#ff0000;"> library project </span>can contain Java classes, Android components and resources. Only assets are not supported.

The<span style="color:#ff0000;"> library project </span>must declare all its components, e.g., activities, service, etc. via the AndroidManifest.xml file. The application which uses the library must also declare all the used components via the AndroidManifest.xml file.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐