android - Caused by: java.lang.NumberFormatException: Invalid double: "["5.0","5.0"]" -
i integrating citrus wallet in company's app , stuck on following error.
the stack trace:
java.lang.runtimeexception: error occured while executing doinbackground() @ android.os.asynctask$3.done(asynctask.java:304) @ java.util.concurrent.futuretask.finishcompletion(futuretask.java:355) @ java.util.concurrent.futuretask.setexception(futuretask.java:222) @ java.util.concurrent.futuretask.run(futuretask.java:242) @ android.os.asynctask$serialexecutor$1.run(asynctask.java:231) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) @ java.lang.thread.run(thread.java:818) caused by: java.lang.numberformatexception: invalid double: "["5.0","5.0"]" @ java.lang.stringtoreal.invalidreal(stringtoreal.java:63) @ java.lang.stringtoreal.initialparse(stringtoreal.java:164) @ java.lang.stringtoreal.parsedouble(stringtoreal.java:282) @ java.lang.double.parsedouble(double.java:301) @ com.citrus.sdk.classes.amount.getvalueasdouble(amount.java:65) @ com.citrus.sdk.payment.paymentbill.<init>(paymentbill.java:90) @ com.citrus.sdk.payment.paymentbill.fromjson(paymentbill.java:261) @ com.citrus.sdk.getjsonbill.doinbackground(getjsonbill.java:70) @ com.citrus.sdk.getjsonbill.doinbackground(getjsonbill.java:22) @ android.os.asynctask$2.call(asynctask.java:292) @ java.util.concurrent.futuretask.run(futuretask.java:237) @ android.os.asynctask$serialexecutor$1.run(asynctask.java:231) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) @ java.lang.thread.run(thread.java:818)
this java code. error occurs after yes clicked in dialog box:
public class fragmentwallet extends dialogfragment implements view.onclicklistener { private context mcontext; private int balance = 1200; button proceed; textview textview; textview log; textview user_bal; citrusclient citrusclient; message text; amount amount = new amount("5.0"); private string bill_url = "my_url" private walletfragmentlistener mlistener; string msg; public fragmentwallet() { } public fragmentwallet(context mcontext) { this.mcontext = mcontext; } public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.wallet_screen, container, false); textview = (textview) rootview.findviewbyid(r.id.user_email); log = (textview) rootview.findviewbyid(r.id.logout); user_bal=(textview) rootview.findviewbyid(r.id.user_balance); proceed = (button) rootview.findviewbyid(r.id.proceed_citrus); msg = paymentdialogfragment.getcitrusclientinstance().getuseremailid(); proceed.setonclicklistener(this); log.setonclicklistener(this); textview.settext(msg); return rootview; } @override public void onclick(view v) { switch (v.getid()) { case r.id.proceed_citrus: oncreatedialog(); break; case r.id.logout: onlogout(); break; } } public void oncreatedialog() { alertdialog.builder builder1 = new alertdialog.builder(mcontext); builder1.setmessage("are sure want proceed?"); builder1.setcancelable(true); builder1.setpositivebutton( "yes", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { //dialog.cancel(); payusingnewcash(); } }); builder1.setnegativebutton( "no", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { dialog.cancel(); } }); alertdialog alert11 = builder1.create(); alert11.show(); } private void payusingnewcash() { log.d("inside", "payusingnewcash"); checkbalance(); } private void checkbalance() { log.d("inside", "payusingnewcash"); paymentdialogfragment.getcitrusclientinstance().getbalance(new callback<amount>() { @override public void success(amount amount) { //get balance amount . balance hardcoded 1200 double bal=(double)amount.getvalueasdouble(); user_bal.settext("your current balance rs."+bal); if (bal >50) { toast.maketext(mcontext,"balance "+bal, toast.length_long).show(); //proceed payment proceedwithpayment(); log.d("inside", "payusingnewcash"); } else { loadmoney loadmoney=new loadmoney(mcontext); fragmentmanager fm=getfragmentmanager(); loadmoney.show(fm,null); } } @override public void error(citruserror error) { toast.maketext(mcontext,"balance not available. please try again",toast.length_long).show(); } }); } public void proceedwithpayment() { // toast.maketext(mcontext,"balance not available. please try again",toast.length_long).show(); log.d("tag","inside proceed"); try { log.d("tag","inside try"); paymentdialogfragment.getcitrusclientinstance().prepaidpay(new paymenttype.citruscash(amount,bill_url),new callback<paymentresponse>() { @override public void success(paymentresponse paymentresponse) { log.d("tag","inside success"); toast.maketext(mcontext,"successful",toast.length_long).show(); } @override public void error(citruserror citruserror) { log.d("tag", citruserror.getmessage()); toast.maketext(mcontext,"not successful.",toast.length_long).show(); } });log.d("tag","++"); } catch (citrusexception e) { log.d("tag",e.tostring()); e.printstacktrace(); } } public void onlogout(){ getdialog().dismiss(); paymentdialogfragment.getcitrusclientinstance().signout(new callback<citrusresponse>() { @override public void success(citrusresponse citrusresponse) { usermanagementfragment usermanagementfragment = new usermanagementfragment(mcontext); fragmentmanager fm=getfragmentmanager(); usermanagementfragment.show(fm,null); } @override public void error(citruserror error) { } }); } }
the method amount.getvalueasdouble():
public double getvalueasdouble() throws numberformatexception { double value = 0.0d; if(!textutils.isempty(this.value)) { value = double.parsedouble(this.value); } return value; }
the entire amount class:
public class amount implements parcelable { private final string value; private final string currency; public static final creator<amount> creator = new creator() { public amount createfromparcel(parcel source) { return new amount(source, null); } public amount[] newarray(int size) { return new amount[size]; } }; public amount(string value) { this.value = value; this.currency = "inr"; } public amount(string value, string currency) { this.value = value; this.currency = currency; } public string getvalue() { return !textutils.isempty(this.value)?this.value.replacefirst("^0+(?!$)", ""):this.value; } public string getcurrency() { return this.currency; } public string getvalueasformatteddouble(string format) throws numberformatexception { decimalformat df = new decimalformat(format); return df.format(this.getvalueasdouble()); } public double getvalueasdouble() throws numberformatexception { double value = 0.0d; if(!textutils.isempty(this.value)) { value = double.parsedouble(this.value); } return value; } public static amount fromjson(string response) { amount amount = null; jsonobject jsonobject = null; if(!textutils.isempty(response)) { try { jsonobject = new jsonobject(response); amount = fromjsonobject(jsonobject); } catch (jsonexception var4) { var4.printstacktrace(); } } return amount; } public static amount fromjsonobject(jsonobject amountobject) { amount amount = null; if(amountobject != null) { string value = amountobject.optstring("value"); string currency = amountobject.optstring("currency"); if(!textutils.isempty(value) && !textutils.isempty(currency)) { amount = new amount(value, currency); } } return amount; } public static string tojson(amount amount) { jsonobject billobject = tojsonobject(amount); return billobject != null?billobject.tostring():null; } public static jsonobject tojsonobject(amount amount) { jsonobject billobject = null; if(amount != null) { try { billobject = new jsonobject(); billobject.put("value", amount.value); billobject.put("currency", amount.currency); } catch (jsonexception var3) { var3.printstacktrace(); } } return billobject; } public int describecontents() { return 0; } public void writetoparcel(parcel dest, int flags) { dest.writestring(this.value); dest.writestring(this.currency); } private amount(parcel in) { this.value = in.readstring(); this.currency = in.readstring(); } public string tostring() { return "amount{value=\'" + this.value + '\'' + ", currency=\'" + this.currency + '\'' + '}'; } public int hashcode() { return super.hashcode(); } public boolean equals(object o) { if(this == o) { return true; } else if(!(o instanceof amount)) { return false; } else { amount amount = (amount)o; return this.getvalueasdouble() == amount.getvalueasdouble() && this.currency.equalsignorecase(amount.getcurrency()); } } }
any highly appreciated
seems in json array of doubles? right?
`"["5.0","5.0"]"`
please check if json correct , if array parse array of doubles instead of 1 double value.
Comments
Post a Comment