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.