Java – Using google translate in android application


I want to use google translate API on my android project. Below are my codes. It works as java project but when I try it on android device, project stopped. What is the reason?
I added googletranslateapi-1.0.jar,

package com.example.calendar;

import com.gtranslate.Language;
import com.gtranslate.Translator;

public class translator {

    public String translate(String text) {
        Translator translate = Translator.getInstance();
        String text2 = translate.translate(text, Language.TURKISH,
        return text2;


In mainactivity

public void onActivityResult(int requestCode, int resultCode, Intent data) 

if (requestCode == VR_REQUEST && resultCode == RESULT_OK) {

            ArrayList<String> suggestedWords = data
            Context context = getApplicationContext();
            text = suggestedWords.get(0);
            int duration = Toast.LENGTH_SHORT;
            ClassificationActivity classificationActivity = new ClassificationActivity();
            String category = classificationActivity.control(text);
            translator trans = new translator();
            String ingtext = trans.translate(text);

            CalendarEvent cv = new CalendarEvent();
            Date date = new Date();
            ContentResolver cr = ctx.getContentResolver();
            Uri uri = cr.insert(Events.CONTENT_URI, CalendarEvent
                    .toICSContentValues(cv, date.getTime(), category));
            Toast toast = Toast.makeText(context, ingtext, duration);


Best Solution

I'm just adding to this question as it is still getting a fair number of views and hasn't seen an accept.

The google-api-translate-java library from the Google Code Archive is out of date and should no longer be used. You should now be using the Translate API Client Library for Java which is a component of the Google API Client Library for Java

An example of usage:

String translatedText = Translate.DEFAULT.execute("Some text", Language.ENGLISH, Language.FRENCH);