I have solved the problem by using the AsynTask
try {
String x = new RetrieveResult().execute().get();
t.setText(x);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
class RetrieveResult extends AsyncTask<String, String, String>
{
private Exception exception;
@Override
protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub
try
{
s = getJson("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22"+val[from]+val[to]+"%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=");
JSONObject jObj;
jObj = new JSONObject(s);
String exResult = jObj.getJSONObject("query").getJSONObject("results").getJSONObject("rate").getString("Rate");
return exResult;
}
catch (Exception e)
{
this.exception = e;
return null;
}
}