I am attempting to make an Android app which imports the LanguageTool java library and detects English grammatical errors.

Despite importing languagetool.jar, I am receiving a ClassDefNotFoundError on org.languagetool.language.AmericanEnglish upon instantiating an AmericanEnglish object. This error only occurs when I try to import LanguageTool in an Android app. When importing the same jar into a java file on my machine, this error does not occur.

If you've downloaded the ZIP, AmericanEnglish.class is not in a JAR, but in the "org" directory. You can ZIP that directory and name it languagetool-2.jar or whatever and it should work. However, if at all possible, I would recommend to use Maven, as documented at http://wiki.languagetool.org/java-api.

I have gotten past the ClassDefNotFoundError, although I am now experiencing a NullPointerException upon initialization of JLanguageTool. My Android error log is telling me that I am getting a NullPointerException in JLanguageTool.getBuildDate (line 111). I have a hunch that this may be related to what appears to be getBuildDate's attempt to open an internet connection.

It's not opening an internet connection, but looking for a file "org/languagetool/JLanguageTool.class", which is usually in a JAR. Maybe the getResource() works differently on Android and cannot find the class for some reason. I suggest you search the web if there is some special behavior in Android for getResource(). I needed, I'll just return null on Android.

One user from this thread posted:"I am not 100% sure but I don't think that this mechanism works under Android as it does in a real JVM (since dalvik is essentially not a JVM). I think (and I might be wrong here), that in the packaged APK, the JAR does no longer exist and therefore your path to the resource probably is wrong. The classes of your JAR are converted to the dex file format and added to the classes.dex file. Therefore you cannot resolve a resource like foo.bar.class because it does not exist in the classpath."

So, it seems that for now I should locally modify getBuildDate to return null? I would prefer this to the cost of having another internet connection request in my app.

The good news is that I am no longer getting any exceptions related to getBuildDate(). However, now my app is refusing to recognize the java.util.Objects class which is clearly contained in my android jar. I believe my my classpath order is set appropriately, so I do not see why this is an issue.

java.util.Objects was introduced with Java 1.7. If Android still only support Java 1.6, that's a problem. You could use LanguageTool 2.2, which was the latest version of LanguageTool that still works with Java 1.6.

I ended up playing around a bit with version 2.2 to get it to finally work. I had to make a few edits, such as changing the ways that model files (i.e. grammar.xml) are read in such that they could be read from an Android apk.

The latency for detecting errors in one 5-7 word sentence on Android (Google Glass, specifically) is surprisingly good. I'm looking at around a 0.5-1 second wait time.

Right now, my code is available publicly on Github, and I'm in the stage of cleaning it up. I would be happy to share this after I see that it's in a presentable state.I have my LanguageTool jar available on Github as part of the libraries required for my app, but I do not have my code modifications to LanguageTool available publicly. Is this something you would be interested in?