API Exception running WordOfTheDay Example

43 views
Skip to first unread message

MS

unread,
Apr 25, 2014, 3:44:12 PM4/25/14
to wordn...@googlegroups.com
Wordnik experts - I could use a bit of your advice.

I'm new to wordnik and trying to do a quick test of the WordOfTheDayAPI but I'm having trouble getting the WordOfTheDay Example to work.  
We don't use Gradle or Maven, so for expediency, I downloaded the wordnik-android-client-4.0.jar file from (http://search.maven.org/#browse%7C601367681)  and put it in my libs directory.
I put my API key in the file, changed the word of the day date to the current date, built & debugged. I'm getting an API exception (stack trace below)

04-25 19:25:39.036: W/System.err(275): com.wordnik.client.common.ApiException: api.wordnik.com
04-25 19:25:39.036: W/System.err(275): at com.wordnik.client.common.ApiInvoker.invokeAPI(ApiInvoker.java:210)
04-25 19:25:39.036: W/System.err(275): at com.wordnik.client.api.WordsApi.getWordOfTheDay(WordsApi.java:97)
04-25 19:25:39.036: W/System.err(275): at com.example.wordnikexample.MainActivity$WordOfTheDayAsyncTask.doInBackground(MainActivity.java:82)
04-25 19:25:39.036: W/System.err(275): at com.example.wordnikexample.MainActivity$WordOfTheDayAsyncTask.doInBackground(MainActivity.java:1)
04-25 19:25:39.036: W/System.err(275): at android.os.AsyncTask$2.call(AsyncTask.java:185)
04-25 19:25:39.036: W/System.err(275): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-25 19:25:39.036: W/System.err(275): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-25 19:25:39.036: W/System.err(275): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
04-25 19:25:39.036: W/System.err(275): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
04-25 19:25:39.036: W/System.err(275): at java.lang.Thread.run(Thread.java:1096)

The code is identical to the example posted here:

class WordOfTheDayAsyncTask extends AsyncTask<Void, Void, WordOfTheDay> {
   @Override
   protected WordOfTheDay doInBackground(Void... params) {
       WordsApi api = new WordsApi();
       
       api.addHeader("api_key", "my_key_here - I removed it for posting");
       
       WordOfTheDay d1 = new WordOfTheDay();
       
       try {
       
          return api.getWordOfTheDay("2014-04-25");
       }
       catch (Exception e) {
         Log.d("WordOfTheDayAsyncTask", e.getMessage());
       
         return null;
       } 
       
       
   }

   @Override
   protected void onPostExecute(WordOfTheDay d) {
       Log.d("WordOfTheDayAsyncTask", d.toString());
   }
}

Any suggestions?  The only think I can think of is that the jar file on the Maven Repository isn't everything I need - do I need to wait until we get Maven or Gradle installed to complete our proof of concept testing?

Tony Tam

unread,
Apr 25, 2014, 3:49:07 PM4/25/14
to wordn...@googlegroups.com
Hi, I strongly suggest you use a dependency manager.  It's really hard to integrate anything without it.

Maven tells me you need to add some other libraries into your project:

mvn dependency:tree

[INFO] Scanning for projects...

[WARNING] 

[WARNING] Some problems were encountered while building the effective model for com.wordnik:wordnik-android-client:jar:4.0

[WARNING] 'build.plugins.plugin.version' for org.codehaus.mojo:build-helper-maven-plugin is missing. @ line 68, column 15

[WARNING] 

[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.

[WARNING] 

[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.

[WARNING] 

[INFO]                                                                         

[INFO] ------------------------------------------------------------------------

[INFO] Building wordnik-android-client 4.0

[INFO] ------------------------------------------------------------------------

[INFO] 

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ wordnik-android-client ---

[INFO] com.wordnik:wordnik-android-client:jar:4.0

[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.1.4:compile

[INFO] +- com.fasterxml.jackson.core:jackson-annotations:jar:2.1.4:compile

[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.1.4:compile

[INFO] +- org.apache.httpcomponents:httpclient:jar:4.0:compile

[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.0.1:compile

[INFO] |  +- commons-logging:commons-logging:jar:1.1.1:compile

[INFO] |  \- commons-codec:commons-codec:jar:1.3:compile

[INFO] +- org.scala-lang:scala-library:jar:2.9.1-1:test

[INFO] +- org.scalatest:scalatest_2.9.1:jar:1.6.1:test

[INFO] \- junit:junit:jar:4.8.1:test

MS

unread,
Apr 25, 2014, 5:50:23 PM4/25/14
to wordn...@googlegroups.com
Tony:

Thanks for the quick response.  Ultimately, I'm sure I will have to use Maven or Grindle for our project, but your answer has me curious. The libraries that are listed below ("maven dependencies") are the same libraries that are listed in the android jar pom file.  If this is true, and the artifact ID in the pom file is wordnik-android-client, then aren't  these the libraries that are needed to create the wordnik-android-client jar file? If so, wouldn't those be incorporated in the jar on the Maven Repository?  

Thanks for your help-

Milo

Tony Tam

unread,
Apr 25, 2014, 8:06:43 PM4/25/14
to wordn...@googlegroups.com
yes, that's the same thing.  If you're using android studio, you can just include a dependency in your build.gradle file:

dependencies {
    compile 'com.wordnik:wordnik-android-client:4.0'
Reply all
Reply to author
Forward
0 new messages