2013-05-23 3 views
0

이 질문은 중복 될 수 있지만 이전 질문에 대한 답변을 찾지 못했습니다.번역을 가져 오는 중 오류가 발생했습니다.

언어를 번역하고 싶습니다. google-api-translate-java-0.97.jar을 사용했습니다.

com.google.api.GoogleAPIException :의 java.lang.Exception : [구글-API-번역 - 자바] 오류 검색 번역

는 내가 같은 오류가 발생했습니다 코드 아래 사용.

자바 코드 :

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 :

<?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> 

답변

관련 문제