1

I need to translate inputed text from one language to another, trying to use this but have problem. This code:

Thread one = new Thread() {
            public void run() {
                try {
                    Translator translate = Translator.getInstance();
                    String text = translate.translate("I am programmer", Language.ENGLISH, Language.PORTUGUESE);
                    Log.d("TEXT: ",text);
                } catch(Exception v) {
                    Log.d("ERR: ", v.toString());
                }
            }
        };
one.start();

Throws error:

W/System.err: java.io.FileNotFoundException: http://translate.google.com.br/translate_a/t?client=t&text=I%20am%20programmer&hl=en&sl=en&tl=pt&multires=1&prev=btn&ssel=0&tsel=0&sc=1
W/System.err:     at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:206)
W/System.err:     at com.gtranslate.utils.WebUtils.source(WebUtils.java:24)
W/System.err:     at com.gtranslate.parsing.ParseTextTranslate.parse(ParseTextTranslate.java:19)
W/System.err:     at com.gtranslate.Translator.translate(Translator.java:37)
W/System.err:     at org.reikartz.mashkov.recyclerview.MainActivity$1$1.run(MainActivity.java:74)

I don't know, what am i doing wrong.

Gertus
  • 53
  • 6
  • can you print some more info? v.printStackTrace(); and edit your post? – EJW Dec 22 '15 at 09:18
  • FileNotFoundException in HttpURLConnection is generally occurred because of bad request or library errors once update all your build.gradel file dependence related and check your manifest permissions. – Ravi Jaggarapu Dec 22 '15 at 10:10

3 Answers3

1

Finally i find out, that http links not valid (in some unknown cause) and desided to use yandex api https://github.com/rmtheis/yandex-translator-java-api

Gertus
  • 53
  • 6
0

The issue is that the language should be installed in your device as well if you need to convert it. The file of Portuguese is not present in your device it is throwing FileNotFoundException.

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
Saurabh sharma
  • 369
  • 2
  • 13
0

I think the actual problem is that java-google-translate-text-to-speech is ancient and does not generate valid HTTP requests (the URL from the stack trace gives a 503, which is why you get the FileNotFoundException from the HttpURLConnnection).

You probably want to use the Translate API v2 Client for Java.

Adam
  • 5,697
  • 1
  • 20
  • 52