title: how to get result value from onPostExecute into mainactivity
body: <p>I am trying to make an app in which i could able to translate a copied string from clipboard, translation is showing in logcat but app is crashing while printing a translation into a Toast
  Here is the code</p>
  
  <pre><code>enter code here
  MainActivity.java
  import android.app.*;
  import android.content.*;
  import android.os.*;
  import android.util.*;
  import com.sk.translater.TranslatorBackgroundTask;
  import java.util.concurrent.*;
  
  public class MainActivity extends Activity 
  {
  
  String def;
  String textToBeTranslated;
  Context context=this;
  
  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      //Default variables for translation
      //String textToBeTranslated = "Compare";
      String languagePair = "en-mr"; 
  
      final ClipboardManager cb = (ClipboardManager)  getSystemService(CLIPBOARD_SERVICE);
      cb.addPrimaryClipChangedListener(new    ClipboardManager.OnPrimaryClipChangedListener(){
  
              @Override
              public void onPrimaryClipChanged()
              {
                  // TODO: Implement this method
                  ClipData clipdata = cb.getPrimaryClip();
                  ClipData.Item item = clipdata.getItemAt(0);
                  if (item.getText() != null)
                  {
                      textToBeTranslated = item.getText().toString();
  
  
                  }
              }
          });
      Translate(textToBeTranslated, languagePair);
  }
  
  //Function for calling executing the Translator Background Task
  void Translate(String textToBeTranslated, String languagePair)
  {
      TranslatorBackgroundTask translatorBackgroundTask= new  TranslatorBackgroundTask(context);
  
          //String translationResult = 
          translatorBackgroundTask.execute(textToBeTranslated, languagePair);// Returns the translated text as a String
          //Log.d("Translation Result",translationResult); // Logs the result in Android Monitor
  
  }
    }
  </code></pre>
  
  <p>Here is the TranslatorBackgroundTask.class which is on github</p>
  
  <pre><code>enter code here
  TranslatorBackgroundTask.java
  public class TranslatorBackgroundTask extends AsyncTask&lt;String, Void, String&gt;
  {
  
  //Declare Context
  Context ctx;
  //Set Context
  TranslatorBackgroundTask(Context ctx)
  {
      this.ctx = ctx;
  }
  
  @Override
  public String doInBackground(String... params)
  {
      //String variables
      String textToBeTranslated = params[0];
      String languagePair = params[1];
  
      String jsonString;
  
      try
      {
          //Set up the translation call URL
          String yandexKey = "[MY_KEY]";
          String yandexUrl = "https://translate.yandex.net/api/v1.5/tr.json/translate?key=" + yandexKey
              + "&amp;text=" + textToBeTranslated + "&amp;lang=" + languagePair;
          URL yandexTranslateURL = new URL(yandexUrl);
  
          //Set Http Conncection, Input Stream, and Buffered Reader
          HttpURLConnection httpJsonConnection = (HttpURLConnection) yandexTranslateURL.openConnection();
          InputStream inputStream = httpJsonConnection.getInputStream();
          BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
  
          //Set string builder and insert retrieved JSON result into it
          StringBuilder jsonStringBuilder = new StringBuilder();
          while ((jsonString = bufferedReader.readLine()) != null)
          {
              jsonStringBuilder.append(jsonString + "\n");
          }
  
          //Close and disconnect
          bufferedReader.close();
          inputStream.close();
          httpJsonConnection.disconnect();
  
          //Making result human readable
          String resultString = jsonStringBuilder.toString().trim();
          //Getting the characters between [ and ]
          resultString = resultString.substring(resultString.indexOf('[') + 1);
          resultString = resultString.substring(0, resultString.indexOf("]"));
          //Getting the characters between " and "
          resultString = resultString.substring(resultString.indexOf("\"") + 1);
          resultString = resultString.substring(0, resultString.indexOf("\""));
  
          Log.d("Translation Result:", resultString);
          Toast.makeText(ctx, "" + resultString, Toast.LENGTH_LONG).show();
  
          return jsonStringBuilder.toString().trim();
      }
      catch (MalformedURLException e)
      {
          e.printStackTrace();
      }
      catch (IOException e)
      {
          e.printStackTrace();
      }
      return null;
  }
  
  @Override
  protected void onPreExecute()
  {
      super.onPreExecute();
  }
  
  @Override
  public void onPostExecute(String result)
  {
      super.onPostExecute(result);    
  }
  
  @Override
  protected void onProgressUpdate(Void... values)
  {
      super.onProgressUpdate(values);
  }    
  </code></pre>
  
  <p>How can i use result value in another class? I tried to search but not solved my problem.   </p>