TextView不返回任何Android



我在Android中有一个函数,其中它获取TextView返回的值,该值是 totalcost_venuetotalcost_appareltotalcost_souvenirtotalcost_caterer

该值将转换为双精度,之后我必须添加这些值。但是当特定TextView不返回任何值时,我遇到了错误。任何帮助都可以。谢谢!

double totalcost_venue_finalconverted = Double.parseDouble(totalcost_venue.getText().toString());
double totalcost_apparel_finalconverted = Double.parseDouble(totalcost_apparel.getText().toString());
double totalcost_caterer_finalconverted = Double.parseDouble(totalcost_caterer.getText().toString());
double totalcost_souvenir_finalconverted =  Double.parseDouble(totalcost_souvenir.getText().toString());
double total = (totalcost_venue_finalconverted + totalcost_apparel_finalconverted + totalcost_caterer_finalconverted +totalcost_souvenir_finalconverted);
String total_all= Double.toString(total);
totalcost_all.setText(total_all);
String totalcost_final = totalcost_all.getText().toString();
double budget_converted = Double.parseDouble(budget_event);
double totalcost_converted = Double.parseDouble(totalcost_final);
if(budget_converted <= totalcost_converted){
                registerErrorMsg.setText(" Oops!! Already exceeded");
如果

Double.parseDouble()接收空值或接收文本,则可能会引发异常。

要解决空值问题,您可以添加以下检查:

double totalcost_venue_finalconverted = 0;
if(!totalcost_venue.getText().toString().equals("")){
    totalcost_venue_finalconverted = Double.parseDouble(totalcost_venue.getText().toString());
}

相关内容

  • 没有找到相关文章

最新更新