-->

BlueMix service error with Android app - 'Unkn

2019-08-10 09:12发布

问题:

I'm developing an android application and am attempting to integrate the Bluemix service - Personality Insights. However, due to a conflict with dates (Bluemix service is assuming a Java SimpleDateFormat which includes the symbol 'X', while Android's SimpleDateFormat does not include this symbol) causing an error (Log below). My question is this, is there a way to brute force the app to use the Java SimpleDateFormat version as opposed the Android version? other than that I don't see how I can use the service without Bluemix switching to accomodate the 'X' character in dates. Any enlightening on this topic would be appreciated!

Log:

Caused by: java.lang.IllegalArgumentException: Unknown pattern character 'X'
            at java.text.SimpleDateFormat.validatePatternCharacter(SimpleDateFormat.java:314)
            at java.text.SimpleDateFormat.validatePattern(SimpleDateFormat.java:303)
            at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:356)
            at com.google.gson.DefaultDateTypeAdapter.<init>(DefaultDateTypeAdapter.java:49)
            at com.google.gson.GsonBuilder.addTypeAdaptersForDate(GsonBuilder.java:555)
            at com.google.gson.GsonBuilder.create(GsonBuilder.java:543)
            at com.ibm.watson.developer_cloud.util.GsonSingleton.createGson(GsonSingleton.java:53)
            at com.ibm.watson.developer_cloud.util.GsonSingleton.getGson(GsonSingleton.java:38)
            at com.ibm.watson.developer_cloud.concept_expansion.v1.ConceptExpansion.createJob(ConceptExpansion.java:147)
            at intercept.notification.notify.MainActivity$PlaceholderFragment$Persona.doInBackground(MainActivity.java:106)
            at intercept.notification.notify.MainActivity$PlaceholderFragment$Persona.doInBackground(MainActivity.java:84)

I've debugged this quite a bit but don't know how to brute force use of the Java version of SimpleDataFormat as opposed the Android version. Differences between the two can be seen here: Java (which includes symbol 'X' as required by Bluemix service - http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

Android (which doesn't include it) - http://developer.android.com/reference/java/text/SimpleDateFormat.html

回答1:

The problem

We were using 'X' which is not supported by the jdk 1.6 in Android.
That problem was fixed in v1.1.1.

Updating the Dependency

  1. Maven:

    <dependency> <groupId>com.ibm.watson.developer_cloud</groupId> <artifactId>java-wrapper</artifactId> <version>1.1.1</version> </dependency>

  2. Gradle:

'com.ibm.watson.developer_cloud:java-wrapper:1.1.1'

  1. Downloading the jar-with-dependencies from github.