0

please help me this code I have used multiple buttons for calculator app but calculation of multiplication function is not working and app is getting crashed

===========================================================

public class MainActivity extends AppCompatActivity {
   TextView ed1;
   boolean isNewOp=true;
   char op = '+';
   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);

       ed1 = findViewById(R.id.edittext);
   }
   public void operatorEvent(View view) {
       isNewOp=false;
       String number = ed1.getText().toString();
       switch(view.getId()){
           case R.id.buttonmult:
               op='*';
               ed1.setText(number+"x"); 
               break;
       }
   public void calculateEvent(View view) {
       String N = ed1.getText().toString();
       int i = N.indexOf(op);
       double a = Double.parseDouble( N.substring(0,i));
       double b = Double.parseDouble(N.substring(i+1,N.length()));
       double result=0;
       switch(op){
           case '*':
               result=a*b;
               break;
       }
       ed1.setText(result+"");
       isNewOp=true;
   }

  • 1
    Does this answer your question? [Unfortunately MyApp has stopped. How can I solve this?](https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this) – a_local_nobody Feb 05 '22 at 08:00

0 Answers0