views:

636

answers:

2

Hi,

I am having a lot of trouble adding the WEKA library to a project I am working on. I have followed several tutorials that explain how to do this including the Android Developers guide:

http://developer.android.com/guide/appendix/faq/commontasks.html#addexternallibrary

and several of the postings on SO.

I have created a folder in my project with the weka.jar file, created a new library (adding the weka.jar file to the library) and included this library in my build path. I have also added the library under the "Order and Export" tab in the project properties.

I have also tried importing the jar file so that the actual contents of the jar are extracted into a directory in my project.

The end result of all of this is that my project is able to build correctly and without error, but when it comes time to run my code on the emulator I get the following exception:

04-10 22:52:21.051: ERROR/dalvikvm(582): Could not find class 'weka.classifiers.trees.J48', referenced from method edu.usc.student.composure.classifier.GaitClassifierImpl.

with J48 being the class I reference in my code.

Does anyone have any additional suggestions that I may have overlooked?

Thanks!

+2  A: 

WEKA is not going to work on Android without changes. J48, for example, requires the java.lang.Cloneable interface, which is not available in Android.

What you need to do is check out the WEKA source code from Subversion, add it to your project (removing the JAR file), compile it, and fix all the compile errors. There may be quite a few of these.

CommonsWare
Thanks for the knowledgeable reply! I've found that it is possible to output Java code that replicates the tree structure of the trained classifier which does not use any Weka classes except for the Instance class (which I can easily replace). I'll just go with that workaround instead of trying to port Weka to Android haha.
mmontalbo
A: 

@ mmontalbo

I am also trying to port WEKA in android, although my program compiles but gives errors at run time, can you please tell me in some detail the solution you found for this..?? How is it possible to output java code that replicates the tree structure of the trained classifier..??

Thanks DT

You can export your tree structure as java code by using the WEKA Experimenter application. Load your arff data file into the app and then classify using your tree structure (in our case it was the J48 tree). Then, go under "More Options" and check the "Output Source Code" checkbox at the bottom. When you click start, at the end of the classification output, you will see a Java class generated for you. You can take this class and use it in your code (maybe with some slight modification).
mmontalbo