java - Get Value out of Try/Catch exception? -
i'm try create simple android application currency exchange , got stuck when got try , catch. wanna value of rate inside try , catch , use it, im unable figure out how possible or if possible. appreciated.
string exchange = "http://rate-exchange.appspot.com/currency?from=" + + "&to=" + + "&q=1"; double rate = 0; jsonobject json; try { json = readjsonfromurl(exchange); for(int = 0; < json.length(); ++) 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));
double rate = 0; // initialize rate jsonobject json; try { // rate = json.getdouble("v"); // calculate values rate, if try fail //before assign value rate 0 } catch (ioexception e) { } catch (jsonexception e) { } total.settext(string.valueof(rate*amount)); // still rate 0 , //wrong calculation
Comments
Post a Comment