vikassharma27 / google-api-translate-java

Automatically exported from code.google.com/p/google-api-translate-java
0 stars 0 forks source link

org.json.JSONException: JSONObject["responseData"] is not a JSONObject #62

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
My simple translation app worked fine with 0.7 but when upgrading to 0.8 I get 
this:

org.json.JSONException: JSONObject["responseData"] is not a JSONObject.
    at org.json.JSONObject.getJSONObject(JSONObject.java:521)
    at com.google.api.translate.Translate.execute(Translate.java:62)

Translating from en to da.

Original issue reported on code.google.com by matsekb...@gmail.com on 21 Aug 2009 at 11:49

GoogleCodeExporter commented 8 years ago
And also, the 0.7 version dosnt work either. It also exits with an exception.

Original comment by matsekb...@gmail.com on 21 Aug 2009 at 11:49

GoogleCodeExporter commented 8 years ago
The exception on 0.7 is:
Caused by: java.lang.ClassCastException: org.json.JSONObject$Null
    at com.google.api.translate.Translate.retrieveTranslation(Translate.java:109)

Original comment by matsekb...@gmail.com on 21 Aug 2009 at 12:03

GoogleCodeExporter commented 8 years ago
What text are you translating?

Original comment by rich.mid...@gmail.com on 21 Aug 2009 at 12:12

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I tranlate simple english texts to danish, for example:
CANCEL
Certificate
Chapter
Condition code
Commodity

Original comment by matsekb...@gmail.com on 21 Aug 2009 at 12:39

GoogleCodeExporter commented 8 years ago
Code:

    public static String translate(String fromLanguage, String toLanguage, String text) {
        String translatedText = "";
        try {
            Language from = findLanguage(fromLanguage);
            Language to = findLanguage(toLanguage);
            translatedText = Translate.translate(text, from, to);
            System.out.println("Google: " + text + " -> " + translatedText);
        } catch (Exception e) {
            e.printStackTrace();
            translatedText = text;
        }
        translatedText = replaceParenteses(translatedText);
        return translatedText;
    }

Original comment by matsekb...@gmail.com on 21 Aug 2009 at 12:40

GoogleCodeExporter commented 8 years ago
Interesting, I just saw this a couple of times.  It's intermittent and extremely
infrequent; retrying the translation call always seems to clear the problem.

org.json.JSONException: JSONObject["responseData"] is not a JSONObject.
        at org.json.JSONObject.getJSONObject(JSONObject.java:521)
        at com.google.api.translate.Translate.execute(Translate.java:62)
        at com.google.api.translate.Translate.translate(Translate.java:72)

This is a trivial i18n sample program; it translates several small English 
words and
phrases to various target languages:

File
Print Preview
Print PDF
Exit
Language
ID
Company
Contact
Address
Add
Delete

Original comment by jimdougl...@gmail.com on 11 Sep 2009 at 10:49

GoogleCodeExporter commented 8 years ago
I've managed to force this case by submitting invalid data and in the next 
version it 
should return a more helpful error message from the translate service.

Hopefully it's fixed from a coding point of view, but if this is reproduced and 
you 
think the error indicates it's a problem in the translation library, or that 
it's a 
case which should make an attempt to retry the translation, then please file a 
new 
issue. Thanks.

Original comment by rich.mid...@gmail.com on 19 Sep 2009 at 8:15