title: Microsoft Translator Error: Error retrieving translation
body: <p>I've been trying make a translator application and I have set up everything accordingly. But still I get this particular error and been trying to solve it for a while.</p>
  
  <pre><code>package mobi.the404.appointed;
  
  import android.content.Intent;
  import android.database.Cursor;
  import android.os.AsyncTask;
  import android.support.v7.app.ActionBarActivity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.Spinner;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import com.memetix.mst.language.Language;
  import com.memetix.mst.translate.Translate;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class TranslateActivity extends ActionBarActivity{
      private TextView textViewReceived;
      private TextView textViewTranslatedText;
      private Spinner spinner;
      private Button buttonTTranslate;
      private Button buttonTBack;
      private String selectedAp;
      private DBAdapter db = new DBAdapter(this);
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_translate);
          Translate.setClientId("ID");
          Translate.setClientSecret("SECRET");
  
          this.setTitle("Translate Appointment");
          Intent intent = getIntent();
          Bundle extras = intent.getExtras();
          if(extras != null) {
              selectedAp = intent.getExtras().getString("selectedAp");
          }
  
          textViewReceived = (TextView) findViewById(R.id.textViewRecieved);
          textViewTranslatedText = (TextView) findViewById(R.id.textViewTranslatedText);
          spinner = (Spinner) findViewById(R.id.spinner);
          buttonTBack = (Button) findViewById(R.id.buttonTBack);
          buttonTTranslate = (Button) findViewById(R.id.buttonTTranslate);
          try {
              loadDetails();
          } catch (Exception e) {
              e.printStackTrace();
          }
  
          buttonTBack.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent intent = new Intent(TranslateActivity.this, AppointedActivity.class);
                  startActivity(intent);
                  try {
                      this.finalize();
                  } catch (Throwable throwable) {
                      throwable.printStackTrace();
                  }
              }
          });
  
          buttonTTranslate.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  try {
                      textViewTranslatedText.setText(translate(textViewReceived.getText().toString(), spinner.getSelectedItem().toString()));
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          });
  
      }
  
      private void loadDetails() throws Exception {
          db.open();
          Cursor item = db.getRecord(selectedAp);
          textViewReceived.append(item.getString(3));
          db.close();
  
  
          List&lt;String&gt; listLangs = new ArrayList&lt;&gt;();
  
          listLangs.add("Arabic");
          listLangs.add("Dutch");
          listLangs.add("German");
          listLangs.add("French");
          listLangs.add("Greek");
          listLangs.add("Hindi");
          listLangs.add("Italian");
          listLangs.add("Portuguese");
          listLangs.add("Thai");
          ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_item, listLangs);
          dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          spinner.setAdapter(dataAdapter);
      }
  
      public String translate(String text, String lang) throws Exception {
          String translatedText = "";
  
          Language send = null;
          if(lang == "Arabic"){
              send = Language.ARABIC;
          } if(lang == "Dutch"){
              send = Language.DUTCH;
          } if(lang == "German"){
              send = Language.GERMAN;
          } if(lang == "French"){
              send = Language.FRENCH;
          } if(lang == "Greek"){
              send = Language.GREEK;
          } if(lang == "Hindi"){
              send = Language.HINDI;
          } if(lang == "Italian"){
              send = Language.ITALIAN;
          } if(lang == "Portuguese"){
              send = Language.PORTUGUESE;
          } if(lang == "Thai"){
              send = Language.THAI;
          }
          Toast.makeText(getApplicationContext(), text, Toast.LENGTH_LONG).show();
          translatedText = Translate.execute(text, send);
          return translatedText;
      }
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.menu_translate, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>
  
  <p>And the error given out is this;</p>
  
  <pre><code>04-03 14:51:41.721  23897-23897/mobi.the404.appointed W/System.err﹕ java.lang.Exception: [microsoft-translator-api] Error retrieving translation : null
  04-03 14:51:41.726  23897-23897/mobi.the404.appointed W/System.err﹕ at com.memetix.mst.MicrosoftTranslatorAPI.retrieveString(MicrosoftTranslatorAPI.java:202)
  04-03 14:51:41.726  23897-23897/mobi.the404.appointed W/System.err﹕ at com.memetix.mst.translate.Translate.execute(Translate.java:61)
  04-03 14:51:41.726  23897-23897/mobi.the404.appointed W/System.err﹕ at com.memetix.mst.translate.Translate.execute(Translate.java:76)
  04-03 14:51:41.726  23897-23897/mobi.the404.appointed W/System.err﹕ at mobi.the404.appointed.TranslateActivity.translate(TranslateActivity.java:129)
  04-03 14:51:41.726  23897-23897/mobi.the404.appointed W/System.err﹕ at mobi.the404.appointed.TranslateActivity$2.onClick(TranslateActivity.java:73)
  04-03 14:51:41.726  23897-23897/mobi.the404.appointed W/System.err﹕ at android.view.View.performClick(View.java:5184)
  04-03 14:51:41.726  23897-23897/mobi.the404.appointed W/System.err﹕ at android.view.View$PerformClick.run(View.java:20910)
  04-03 14:51:41.726  23897-23897/mobi.the404.appointed W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:739)
  04-03 14:51:41.726  23897-23897/mobi.the404.appointed W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
  04-03 14:51:41.726  23897-23897/mobi.the404.appointed W/System.err﹕ at android.os.Looper.loop(Looper.java:145)
  04-03 14:51:41.726  23897-23897/mobi.the404.appointed W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5942)
  04-03 14:51:41.726  23897-23897/mobi.the404.appointed W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
  04-03 14:51:41.726  23897-23897/mobi.the404.appointed W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
  04-03 14:51:41.726  23897-23897/mobi.the404.appointed W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
  04-03 14:51:41.726  23897-23897/mobi.the404.appointed W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
  04-03 14:51:41.726  23897-23897/mobi.the404.appointed W/System.err﹕ Caused by: android.os.NetworkOnMainThreadException
  04-03 14:51:41.736  23897-23897/mobi.the404.appointed W/System.err﹕ at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
  04-03 14:51:41.736  23897-23897/mobi.the404.appointed W/System.err﹕ at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
  04-03 14:51:41.736  23897-23897/mobi.the404.appointed W/System.err﹕ at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
  04-03 14:51:41.736  23897-23897/mobi.the404.appointed W/System.err﹕ at java.net.InetAddress.getAllByName(InetAddress.java:215)
  04-03 14:51:41.736  23897-23897/mobi.the404.appointed W/System.err﹕ at com.android.okhttp.HostResolver$1.getAllByName(HostResolver.java:29)
  04-03 14:51:41.736  23897-23897/mobi.the404.appointed W/System.err﹕ at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:232)
  04-03 14:51:41.736  23897-23897/mobi.the404.appointed W/System.err﹕ at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:124)
  04-03 14:51:41.736  23897-23897/mobi.the404.appointed W/System.err﹕ at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:367)
  04-03 14:51:41.736  23897-23897/mobi.the404.appointed W/System.err﹕ at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:295)
  04-03 14:51:41.736  23897-23897/mobi.the404.appointed W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:373)
  04-03 14:51:41.736  23897-23897/mobi.the404.appointed W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106)
  04-03 14:51:41.736  23897-23897/mobi.the404.appointed W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:208)
  04-03 14:51:41.736  23897-23897/mobi.the404.appointed W/System.err﹕ at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
  04-03 14:51:41.736  23897-23897/mobi.the404.appointed W/System.err﹕ at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:25)
  04-03 14:51:41.736  23897-23897/mobi.the404.appointed W/System.err﹕ at com.memetix.mst.MicrosoftTranslatorAPI.getToken(MicrosoftTranslatorAPI.java:133)
  04-03 14:51:41.736  23897-23897/mobi.the404.appointed W/System.err﹕ at com.memetix.mst.MicrosoftTranslatorAPI.retrieveResponse(MicrosoftTranslatorAPI.java:160)
  04-03 14:51:41.736  23897-23897/mobi.the404.appointed W/System.err﹕ at com.memetix.mst.MicrosoftTranslatorAPI.retrieveString(MicrosoftTranslatorAPI.java:199)
  04-03 14:51:41.736  23897-23897/mobi.the404.appointed W/System.err﹕ ... 14 more
  04-03 14:52:45.296  23897-23897/mobi.the404.appointed V/ActivityThread﹕ updateVisibility : ActivityRecord{2c2786f6 token=android.os.BinderProxy@3379767a {mobi.the404.appointed/mobi.the404.appointed.TranslateActivity}} show : true
  </code></pre>
  
  <p>The application doesn't crash but the error is given. What am I doing wrong?</p>
  
  <p>PS: I have given the permission for internet access in the manifest.</p>
  
  <p>Thank you.ID</p>