Android 检索翻译时出错

Android 检索翻译时出错,android,android-layout,google-translate,Android,Android Layout,Google Translate,也许这个问题是重复的,但我没有从老问题中找到任何解决方案 我想翻译语言,我使用了google-api-translate-java-0.97.jar 我使用了下面的代码,我得到的错误如下: com.google.api.GoogleAPIException:java.lang.Exception: [google api translate java]检索翻译时出错 Java代码: public class MainActivity extends Activity { EditTex

也许这个问题是重复的,但我没有从老问题中找到任何解决方案

我想翻译语言,我使用了
google-api-translate-java-0.97.jar

我使用了下面的代码,我得到的错误如下:

com.google.api.GoogleAPIException:java.lang.Exception: [google api translate java]检索翻译时出错

Java代码:

public class MainActivity extends Activity {

    EditText MyInputText;
    Button MyTranslateButton;
    TextView MyOutputText;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        MyInputText = (EditText) findViewById(R.id.InputText);
        MyTranslateButton = (Button) findViewById(R.id.TranslateButton);
        MyOutputText = (TextView) findViewById(R.id.OutputText);

        MyTranslateButton.setOnClickListener(MyTranslateButtonOnClickListener);
    }

    private Button.OnClickListener MyTranslateButtonOnClickListener = new Button.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            String InputString;
            String OutputString = null;
            InputString = MyInputText.getText().toString();

            try {


                GoogleAPI.setHttpReferrer("http://www.google.com");
                GoogleAPI.setKey("AIzaSyCr9C8xNq0uODvZMNH_0Jb7BZpBCZMagOo");

                OutputString = Translate.DEFAULT. execute(InputString, Language.ENGLISH,
                        Language.FILIPINO);
            } catch (Exception ex) {
                Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
                ex.printStackTrace();
                OutputString = "Error";
            }

            MyOutputText.setText(OutputString);

        }

    };

}
XML:



该程序是正确的,可能是因为你不知道新闻。谷歌宣布将关闭多个API,包括翻译。 也许它能帮助你

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 >
<TextView
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="hello"
 />
<EditText
android:id="@+id/InputText"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
/>
<Button
android:id="@+id/TranslateButton"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="Translate"
/>
<TextView
android:id="@+id/OutputText"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 />
</LinearLayout>