0

I have just started using eclipse adt(android developer tool) and i am working on electricbill calculator app. The app interface looks like this: App interface

The user will input a value in previous consumption and current consumption then calculate(1st button) to get the total consumption. Then enter the rate and compute(2nd button, multiplies total consumption and rate) to get the electricbill.

My main activity contains onClickListeners for the buttons. The first part of the calculation works, but when i try to input a value and rate and compute it, the application crashes and i dont know where is the problem. Here is my code:

Calculate Button

public class MainActivity extends Activity {

    EditText PrevConEdt, CurrConEdt, RateEdt;
    TextView ConsumptionTv, ElectricBillTv;
    Button CalculateBtn, ComputeBtn, ClearBtn, ClearBtn2;
    Double rateDbl, cbillDbl, consumptionDbl, prevDbl, currentDbl;

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        PrevConEdt = (EditText) findViewById(R.id.txtPreviousConsumption);
        CurrConEdt = (EditText) findViewById(R.id.txtCurrentConsumption);
        RateEdt = (EditText) findViewById(R.id.txtEnterRate);
        
        ConsumptionTv = (TextView) findViewById(R.id.txtConsumption);
        ElectricBillTv = (TextView) findViewById(R.id.txtEbill);
        
        CalculateBtn = (Button) findViewById(R.id.btnCalculate);
        CalculateBtn.setOnClickListener(new View.OnClickListener() {
            
            @Override
            public void onClick(View Calculate) {
                
                String prev, current, consumption;
                 prev = PrevConEdt.getText().toString();
                 current = CurrConEdt.getText().toString();
                 
                 if(PrevConEdt.length() == 0){
                     Toast.makeText(MainActivity.this, "Consumption Required", Toast.LENGTH_LONG).show();
                     return;
                 }else if(CurrConEdt.length() == 0){
                     Toast.makeText(MainActivity.this, "Consumption Required", Toast.LENGTH_LONG).show();
                     return;
                     
                 }else{
                     Double prevDbl, currentDbl, consumptionDbl;
                     prevDbl = Double.parseDouble(prev);
                     currentDbl = Double.parseDouble(current);

                     
                     if(currentDbl < prevDbl){
                         //String msg = "Current should be greater than previous.";
                         //int duration = Toast.LENGTH_LONG;
                         //Toast.makeText(getBaseContext(), msg, duration).show();
                         //PrevConEdt.requestFocus();
                         CurrConEdt.setError("Current should be greater than previous.");
                         return;
                         
                         
                     }else{
                         consumptionDbl = currentDbl - prevDbl;
                         String consumptionStr = String.format("%.2f kWh", consumptionDbl);
                         ConsumptionTv.setText(consumptionStr);
                     }
                     
                     
                     
                     
                     
                 }
                 
                 
            } 
            
            
            
            
            
            
        });

Compute Button

ComputeBtn = (Button) findViewById(R.id.btnCompute);
        ComputeBtn.setOnClickListener(new View.OnClickListener() {
            
            @Override
            public void onClick(View compute) {
                
                
                String rate, consumption;
                rate = RateEdt.getText().toString();
                consumption = ConsumptionTv.getText().toString();
                
                if(RateEdt.length() == 0){
                    RateEdt.setError("Rate is required.");
                    return;
                }else{
                    Double rateDbl, cbillDbl, consumptionDbl;
                    rateDbl = Double.parseDouble(rate);
                    consumptionDbl = Double.parseDouble(consumption);
                    
                    
                    cbillDbl = consumptionDbl *  rateDbl;
                    String billStr = String.format("Php %.2f", cbillDbl);
                    ElectricBillTv.setText(billStr);
                    
                    
                }
                
                
            }
        });
2
  • Share your crash log. Commented Jan 9, 2023 at 14:08
  • Hi, Im not sure if this ist !ENTRY org.eclipse.jdt.ui 4 10001 2023-01-09 22:58:20.767 !MESSAGE Internal Error !STACK 1 Java Model Exception: Java Model Status [Unknown javadoc format for TextView [in TextView.class [in android.widget [in C:\Users\TOSHIBA SAT-C655 PC\Downloads\MOBILE APP\EclipseADT\sdk\platforms\android-17\android.jar]]]] !SUBENTRY 1 org.eclipse.jdt.core 4 1009 2023-01-09 22:58:20.767 !MESSAGE Unknown javadoc format for TextView [in TextView.class [in android.widget [in C:\Users\TOSHIBA SAT-C655 PC\Downloads\MOBILE APP\EclipseADT\sdk\platforms\android-17\android.jar]]] Commented Jan 9, 2023 at 15:12

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.