当删除文本更改后的侦听器中的值时,我的应用程序崩溃

时间:2018-03-07 14:17:21

标签: java android

当我删除e2中的值以进行另一次计算时,应用程序将崩溃,因为e4和e5正在尝试对非数字执行计算,我应该添加什么代码?

private void hookButtons() {                                                                

    e2 = findViewById(R.id.SalePriceNum);                                                   
    e4 = findViewById(R.id.ebayFeeNum);                                                     
    e5 = findViewById(R.id.paypalFeeNum);                                                   


    e2.addTextChangedListener(new TextWatcher() {                                           
        @Override                                                                           
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {    

        }                                                                                   

        @Override                                                                           
        public void onTextChanged(CharSequence s, int start, int before, int count) {       

        }                                                                                   

        @Override                                                                           
        public void afterTextChanged(Editable s) {                                          
            if (e2.getText().toString() != "")                                              
            {                                                                               
                double salePrice = Double.parseDouble(e2.getText().toString());             
                double ebayFee = salePrice / 10.00;                                         
                double paypalFee = (salePrice * 0.034) + 0.2;                               
                double roundedPPFee = Math.round(paypalFee*100.00)/100.00;                  
                double roundedEbayFee = Math.round(ebayFee*100.00)/100.00;                  
                e4.setText(String.valueOf(roundedEbayFee));                                 
                e5.setText(String.valueOf(roundedPPFee));                                   

            }                                                                               
        }                                                                                   

            });                                                                             
    }                                                                                       

0 个答案:

没有答案