Importing Class from External Jar, Android

扶醉桌前 提交于 2020-01-11 10:22:11

问题


I created a new library and added the jars from web harvester to do a bit of web scraping in my android project. in my main activity I import classes that I need. but starting the project on my phone I get a

08-23 08:28:09.763: ERROR/dalvikvm(2123): Could not find class 'org.webharvest.definition.ScraperConfiguration', referenced from method html.parser.MainActivity.onCreate

any ideas?


回答1:


Take a look here http://developer.android.com/guide/appendix/faq/commontasks.html#addexternallibrary are you placing the jar in subfolder of your project ?




回答2:


I had a problem where a jar was not exported to the apk. I manually edited .classpath and added exported="true" to the classpathentry; seems to have fixed my similar problem.

<classpathentry kind="lib" exported="true" path="lib/gson-1.7.1.jar"/>



回答3:


Well, first thing is to check that the library has the right java version. android only support 1.6 and not 1.7 (SDK dependent, but if you want it to work under 2.33, use 1.6) . after that, just drag the file to the libs folder, and select copy. Then, click project properties (right click on the project->properties)-> java build path->libraries tab. in this tab click add JARs and not add external JARs. Select the jar file from your project under the libs folder. If you are still getting the error, make sure your jar file java version is 1.6.



来源:https://stackoverflow.com/questions/3545185/importing-class-from-external-jar-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!