2

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?

DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601
  • Did you created your lib packge on your own or using eclipse IDE? – Praveen Aug 23 '10 at 06:37
  • @Praveen well actually I followed these instructions http://www.cuteandroid.com/tips-for-android-developer-conversion-to-dalvik-format-failed-unable-to-execute-dex-null because I had a strange problem on using external jars in an android project, but yes I used eclipse – DarkLeafyGreen Aug 23 '10 at 07:10
  • possible duplicate of [NoClassDefFoundError Android](http://stackoverflow.com/questions/8678630/noclassdeffounderror-android) – Flow Dec 10 '13 at 14:41

3 Answers3

4

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"/>
Johnny O
  • 587
  • 4
  • 4
  • oh wow, I can't thank you enough, I was having the same problem as you, I used this fix, cleaned and built my project, and now I'm back up and running again, thanks! :-D – Jared May 01 '12 at 22:56
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.

donald
  • 489
  • 5
  • 13
3

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

Mojo Risin
  • 8,136
  • 5
  • 45
  • 58
  • well I created a user lib just as described in you link, I can access the classes in the lib and use them in my code. but when I run the project I get the error. so it seems that the classes are missing in the runtime – DarkLeafyGreen Aug 23 '10 at 13:38
  • You can use the classes because you included the jar in eclipse build path and you got the error because the jar is not exported in your .apk file. Create libs folder from the root of your project and place the jar there the eclipse plugin should export it automatically in the .apk file. – Mojo Risin Aug 23 '10 at 14:27
  • 1
    right click on project -> create folder libs -> place you jar here -> edit your build path to use this location -> right click export to android project or something like this :) – Mojo Risin Aug 23 '10 at 21:14
  • ok, but there is another problem when I do this. eclipse is building workspace, and stucks at 22% it takes about 5 minutes and I get an error "Converting to dalvik format failed" – DarkLeafyGreen Aug 24 '10 at 07:02
  • Android is not using dalvik virtual machine so only jars that are build for dalvik can be used. Build your jar using eclipse from source . – Mojo Risin Aug 24 '10 at 11:07