1

我正在尝试为货币兑换创建一个简单的 android 应用程序,但当我尝试并抓住时我被卡住了。我想从 try and catch 中获取 rate 的值并使用它,但我无法弄清楚这是如何可能的或是否可能。任何帮助,将不胜感激。

        String exchange = "http://rate-exchange.appspot.com/currency?from=" + FROM + "&to=" + TO + "&q=1";

        double RATE = 0;

            JSONObject json;
            try {
                json = readJsonFromUrl(exchange);
                for(int i = 0; i < json.length(); i ++)
                    RATE = json.getDouble("v");
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (JSONException e) {
                // TODO Auto-generated catch block

                e.printStackTrace();
            }

            total.setText(String.valueOf(RATE*AMOUNT));
4

2 回答 2

1
double RATE = 0; // initialize RATE

JSONObject json;
try {
    // do something
     RATE = json.getDouble("v"); // calculate values for RATE, if try fail 
                                 //before assign value RATE will be 0
 } catch (IOException e) {

 } catch (JSONException e) {

 }finnally
{
   \\ Set Rate Here
}
于 2013-08-20T06:50:46.217 回答
0
double RATE = 0; // initialize RATE

JSONObject json;
try {
    // do something
     RATE = json.getDouble("v"); // calculate values for RATE, if try fail 
                                 //before assign value RATE will be 0
 } catch (IOException e) {

 } catch (JSONException e) {

 }

 total.setText(String.valueOf(RATE*AMOUNT)); // so still RATE 0 and 
                                             //wrong calculation
于 2013-08-20T05:09:19.687 回答