title: I cant use Google Translate API in my Android Studio
body: <p>I am trying to create a translation app that uses google translate api and I keep on having error in my program here. I really do not know what to do, in the error it states that &quot;Create method 'translate' in 'Translate'. I am not trying to create a method, but rather it should accept the language code to be translated.</p>
  <pre><code>translate.translate(
                              txtEdit,
                              TranslateOption.sourceLanguage(firstLang),
                              TranslateOption.targetLanguage(secondLang));
  </code></pre>
  <p>Here is my whole class</p>
  <pre><code>public class Translate extends AppCompatActivity {
  
      TextView txtlogo;
      private Spinner spnFrom, spnTo;
      private MaterialButton btnTranslate;
      private TextInputEditText txtEdit, txtOutput;
      private String originalText;
      private String translatedText;
      String fromChoice, toChoice;
      String firstLang,secondLang;
  
      Translate translate;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
          setContentView(R.layout.activity_translate);
  
          //HOOKS
          spnFrom = findViewById(R.id.spnTfrom);
          spnTo = findViewById(R.id.spnTto);
          btnTranslate = findViewById(R.id.btnTtranslate);
          txtEdit = findViewById(R.id.txtTeditsource);
          txtOutput = findViewById(R.id.txtTtranslatedsource);
  
          ArrayAdapter&lt;CharSequence&gt; fromadapter = ArrayAdapter.createFromResource(this, R.array.language, R.layout.spinner_layout);
          fromadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          spnFrom.setAdapter(fromadapter);
          spnTo.setAdapter(fromadapter);
  
          btnTranslate.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  getTranslateService();
                  Translate translate = (Translate) TranslateOptions.getDefaultInstance().getService();
  
                  spnFrom.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                      @Override
                      public void onItemSelected(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
                          fromChoice = adapterView.getItemAtPosition(i).toString();
                          if (fromChoice.equals(&quot;Select Language&quot;)){
                              Toast.makeText(getApplicationContext(), &quot;Please select a language (from)&quot;, Toast.LENGTH_LONG).show();
                          } else if (fromChoice.equals(&quot;Bisaya&quot;)){
                              firstLang = &quot;ceb&quot;;
                          } else firstLang = &quot;tl&quot;;
                      }
  
                      @Override
                      public void onNothingSelected(AdapterView&lt;?&gt; adapterView) {
                          Toast.makeText(getApplicationContext(), &quot;Please select a language (from)&quot;, Toast.LENGTH_LONG).show();
                      }
                  });
  
                  spnTo.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                      @Override
                      public void onItemSelected(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
                          toChoice = adapterView.getItemAtPosition(i).toString();
                          if (toChoice.equals(&quot;Select Language&quot;)){
                              Toast.makeText(getApplicationContext(), &quot;Please select a language (from)&quot;, Toast.LENGTH_LONG).show();
                          } else if (fromChoice.equals(&quot;Tagalog&quot;)){
                              secondLang = &quot;tl&quot;;
                          } else secondLang = &quot;ceb&quot;;
                      }
  
                      @Override
                      public void onNothingSelected(AdapterView&lt;?&gt; adapterView) {
                          Toast.makeText(getApplicationContext(), &quot;Please select a language (from)&quot;, Toast.LENGTH_LONG).show();
                      }
                  });
  
                  Translation translation =
                          translate.translate(
                                  txtEdit,
                                  TranslateOption.sourceLanguage(firstLang),
                                  TranslateOption.targetLanguage(secondLang));
  
  
              }
          });
      }
  
  
      public void getTranslateService() {
  
          StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
          StrictMode.setThreadPolicy(policy);
  
          try (InputStream is = getResources().openRawResource(R.raw.credentials)) {
  
              //Get credentials:
              final GoogleCredentials myCredentials = GoogleCredentials.fromStream(is);
  
              //Set credentials and get translate service:
              TranslateOptions translateOptions = TranslateOptions.newBuilder().setCredentials(myCredentials).build();
  
          } catch (IOException ioe) {
              ioe.printStackTrace();
          }
      }
  } ```
  </code></pre>