Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7929481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:05:34+00:00 2026-06-03T20:05:34+00:00

i have 5 textedits for numbers and a button. when the button is clicked

  • 0

i have 5 textedits for numbers and a button. when the button is clicked the app calculates a different equation based on which field was left empty. however the app keeps crashing when i leave multiple fields empty with the error that the first double in the first if statement is invalid.

idea of the code

if (first field.getText().toString().equals("")) {...}
else if (second field.getText().toString().equals("")) {...}
else if (third field.getText().toString().equals("")) {...}
else if (fourth field.getText().toString().equals("")) {...}
else if (fifth.getText().toString().equals("")) {...}
else {...}

basically the last one should just give a toast for if it isn’t any of the above (2-5 empties, 0 empties

real syntax is this:

    calc.setOnClickListener(new OnClickListener() {         
            public void onClick(View v) {
                EditText fv = (EditText) findViewById(R.id.pv_fv);
                EditText pv = (EditText) findViewById(R.id.pv_pv);
                EditText r = (EditText) findViewById(R.id.pv_discountrate);
                EditText n = (EditText) findViewById(R.id.pv_periods);
                EditText t = (EditText) findViewById(R.id.pv_years);



                if (fv.getText().toString().equals("")) {
                    double r1 = Double.parseDouble(r.getText().toString());
                    double n1 = Double.parseDouble(n.getText().toString());
                    double t1 = Double.parseDouble(t.getText().toString());
                    double pv1 = Double.parseDouble(pv.getText().toString());
                    double answer1 = pv1*(Math.pow(1+(r1/n1) ,n1*t1 ));
                    answer1 = (double)(Math.round(answer1*100))/100;
                    TextView answer = (TextView) findViewById(R.id.pv_answer);
                    answer.setText("The Future Value of the cash flow is: "+answer1);
                }

                else if (pv.getText().toString().equals("")) {
                    double fv1 = Double.parseDouble(fv.getText().toString());
                    double r1 = Double.parseDouble(r.getText().toString());
                    double n1 = Double.parseDouble(n.getText().toString());
                    double t1 = Double.parseDouble(t.getText().toString());
                    double answer1 = fv1/(Math.pow(1+(r1/n1) ,n1*t1 ));
                    answer1 = (double)(Math.round(answer1*100))/100;
                    TextView answer = (TextView) findViewById(R.id.pv_answer);
                    answer.setText("The Present Value of the cash flow is: "+answer1);                      
                }

                else if (r.getText().toString().equals("")){
                    double fv1 = Double.parseDouble(fv.getText().toString());
                    double pv1 = Double.parseDouble(pv.getText().toString());
                    double n1 = Double.parseDouble(n.getText().toString());
                    double t1 = Double.parseDouble(t.getText().toString());
                    double answer1 = ( (Math.pow(fv1/pv1, 1/(n1*t1) ) ) -1)*n1 ;
                    answer1 = (double)(Math.round(answer1*100))/100;
                    TextView answer = (TextView) findViewById(R.id.pv_answer);
                    answer.setText("The discount rate / interest rate applied is: "+answer1);
                }

                else if (t.getText().toString().equals("")){
                    double fv1 = Double.parseDouble(fv.getText().toString());
                    double pv1 = Double.parseDouble(pv.getText().toString());
                    double n1 = Double.parseDouble(n.getText().toString());
                    double r1 = Double.parseDouble(r.getText().toString());
                    double answer1 = Math.log(fv1/pv1) / (n1* Math.log(1+(r1/n1) ) ) ;
                    answer1 = (double)(Math.round(answer1*100))/100;
                    TextView answer = (TextView) findViewById(R.id.pv_answer);
                    answer.setText("The number of years is: "+answer1);
                }

                else if(n.getText().toString().equals("")){
                    Toast errormsg = Toast.makeText(PresentValue.this, "Sorry but Number of Periods cannot be computed.", 5000);
                    errormsg.setGravity(Gravity.CENTER, 0, 0);
                    errormsg.show();
                }

                else {
                    Toast errormsg = Toast.makeText(PresentValue.this, "You either left too many fields empty or filled all of them.", 5000);
                    errormsg.setGravity(Gravity.CENTER, 0, 0);
                    errormsg.show();
                }

            }           
        });

Any idea on what’s wrong with this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:05:36+00:00Added an answer on June 3, 2026 at 8:05 pm

    This is how I solved it. However it seems really … stuffy. is there a way to make it more seemless?

    //clickhandler
            calc.setOnClickListener(new OnClickListener() {         
                public void onClick(View v) {
                    EditText fv = (EditText) findViewById(R.id.pv_fv);
                    EditText pv = (EditText) findViewById(R.id.pv_pv);
                    EditText r = (EditText) findViewById(R.id.pv_discountrate);
                    EditText n = (EditText) findViewById(R.id.pv_periods);
                    EditText t = (EditText) findViewById(R.id.pv_years);
                    TextView answer = (TextView) findViewById(R.id.pv_answer);
                    int filledfields = 0;
    
                    if (fv.getText().toString().equals("")){
                        filledfields ++;
                    }
                    if (pv.getText().toString().equals("")) {
                        filledfields ++;
                    }
                    if (r.getText().toString().equals("")) {
                        filledfields ++;
                    }
                    if (t.getText().toString().equals("")) {
                        filledfields ++;
                    }
                    if (n.getText().toString().equals("")) {
                        filledfields ++;
                    }
    
                    if (filledfields > 1){
                        Toast errormsg = Toast.makeText(PresentValue.this, "Sorry but you left more than one field empty.", 5000);
                        errormsg.setGravity(Gravity.CENTER, 0, 0);
                        errormsg.show();
                    }
    
                    else if (fv.getText().toString().equals("")) {
                        double r1 = Double.parseDouble(r.getText().toString());
                        double n1 = Double.parseDouble(n.getText().toString());
                        double t1 = Double.parseDouble(t.getText().toString());
                        double pv1 = Double.parseDouble(pv.getText().toString());
                        double answer1 = pv1*(Math.pow(1+(r1/n1) ,n1*t1 ));
                        answer1 = (double)(Math.round(answer1*100))/100;
    
                        answer.setText("The Future Value of the cash flow is: "+answer1);
                    }
    
                    else if (pv.getText().toString().equals("")) {
                        double fv1 = Double.parseDouble(fv.getText().toString());
                        double r1 = Double.parseDouble(r.getText().toString());
                        double n1 = Double.parseDouble(n.getText().toString());
                        double t1 = Double.parseDouble(t.getText().toString());
                        double answer1 = fv1/(Math.pow(1+(r1/n1) ,n1*t1 ));
                        answer1 = (double)(Math.round(answer1*100))/100;
    
                        answer.setText("The Present Value of the cash flow is: "+answer1);                      
                    }
    
                    else if (r.getText().toString().equals("")){
                        double fv1 = Double.parseDouble(fv.getText().toString());
                        double pv1 = Double.parseDouble(pv.getText().toString());
                        double n1 = Double.parseDouble(n.getText().toString());
                        double t1 = Double.parseDouble(t.getText().toString());
                        double answer1 = ( (Math.pow(fv1/pv1, 1/(n1*t1) ) ) -1)*n1 ;
                        answer1 = (double)(Math.round(answer1*100))/100;
    
                        answer.setText("The discount rate / interest rate applied is: "+answer1);
                    }
    
                    else if (t.getText().toString().equals("")){
                        double fv1 = Double.parseDouble(fv.getText().toString());
                        double pv1 = Double.parseDouble(pv.getText().toString());
                        double n1 = Double.parseDouble(n.getText().toString());
                        double r1 = Double.parseDouble(r.getText().toString());
                        double answer1 = Math.log(fv1/pv1) / (n1* Math.log(1+(r1/n1) ) ) ;
                        answer1 = (double)(Math.round(answer1*100))/100;
    
                        answer.setText("The number of years is: "+answer1);
                    }
    
                    else if(n.getText().toString().equals("")){
                        Toast errormsg = Toast.makeText(PresentValue.this, "Sorry but Number of Periods cannot be computed.", 5000);
                        errormsg.setGravity(Gravity.CENTER, 0, 0);
                        errormsg.show();
                    }
    
                    else {
                        Toast errormsg = Toast.makeText(PresentValue.this, "You either left too many fields empty or filled all of them.", 5000);
                        errormsg.setGravity(Gravity.CENTER, 0, 0);
                        errormsg.show();
                    }
    
                }           
            });
            //clickhandler end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two button with different commands <asp:LinkButton ID=lbEditDetails Text=Edit... runat=server CommandName=EditDetails CssClass=EditAdults CommandArgument=<%#
I have a txt plain file that has a list of numbers. One number
I have the following which opens TextEdit using a Cocoa objective-c application: [[NSWorkspace sharedWorkspace]
In my app, i have a customize dialog from where i am getting the
I have a activity on my app, that shows a lot of options that
I have rich-text file with a few images and text. In my Cocoa app
WPF has PasswordBox which receives password input into a SecureString, but I have a
I have a deque type list (a queue) which I'd like to show and
I'm trying to get a pyside button to copy text from a qlineEdit field
I have several text edits in a table layout. With small values, the TextEdits

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.