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 7734701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:18:59+00:00 2026-06-01T07:18:59+00:00

Everything works with no errors, but in the xml, tvfinalgrade stays 0.0… Why isn’t

  • 0

Everything works with no errors, but in the xml, tvfinalgrade stays 0.0… Why isn’t the double fin being displayed? I’m sure about what order the tvfin code lines should be written, but I’m assuming its not right.

public class GFActivity extends Activity {
public double fin;
 @Override
    public void onCreate(Bundle savedInstanceState) {          

        super.onCreate(savedInstanceState);    
        setContentView(R.layout.getfinal);

        double q1, q2, ex;
         EditText etq1, etq2, eteg;
         etq1 = (EditText)findViewById(R.id.editText1);
            try{
                q1 = Double.parseDouble(etq1.getText().toString());
            } catch (NumberFormatException e) {
                q1=0;
            }
         etq2 = (EditText)findViewById(R.id.editText2);
            try{
                q2 = Double.parseDouble(etq2.getText().toString());
            } catch (NumberFormatException e){
                q2 = 0;
            }
         eteg = (EditText)findViewById(R.id.editText3);
         try{
             ex = Double.parseDouble(eteg.getText().toString());
         } catch (NumberFormatException e){
             ex = 0;
         }
        fin = 0.4*q1+0.4*q2+0.2*ex;
            if(fin == (int)fin){
                System.out.println((int)fin);
            }
            else{
                fin = 0.01*((int)(fin*100));
                System.out.println(fin);
            } 
            Button solve = (Button)findViewById(R.id.getfinbutton);
            solve.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    TextView tvfin= TextView)findViewById(R.id.tvfinalgrade);
                         tvfin.setText(fin+"");
                }
            });


    }
}
  • 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-01T07:19:00+00:00Added an answer on June 1, 2026 at 7:19 am

    When you start the app, in the onCreate() you already parse the EditText content(which are empty, so you throw NumberFormatException and your fin variable ends up as 0) and when you get to the part of setting the result(the user clicks the Button) you set the fin which is currently 0 to the TextView(the problem is that when the user clicks the Button you never get the current EditText content to do any calculation and the fin variable is the old value(0)). Move your calculation in the onClick() method:

    Button solve = (Button)findViewById(R.id.getfinbutton);
                solve.setOnClickListener(new OnClickListener() {
    
                    public void onClick(View v) {
                       double q1, q2, ex;
             EditText etq1, etq2, eteg;
             etq1 = (EditText)findViewById(R.id.editText1);
                try{
                    q1 = Double.parseDouble(etq1.getText().toString());
                } catch (NumberFormatException e) {
                    q1=0;
                }
             etq2 = (EditText)findViewById(R.id.editText2);
                try{
                    q2 = Double.parseDouble(etq2.getText().toString());
                } catch (NumberFormatException e){
                    q2 = 0;
                }
             eteg = (EditText)findViewById(R.id.editText3);
             try{
                 ex = Double.parseDouble(eteg.getText().toString());
             } catch (NumberFormatException e){
                 ex = 0;
             }
            fin = 0.4*q1+0.4*q2+0.2*ex;
                if(fin == (int)fin){
                    System.out.println((int)fin);
                }
                else{
                    fin = 0.01*((int)(fin*100));
                    System.out.println(fin);
                } 
                        TextView tvfin= TextView)findViewById(R.id.tvfinalgrade);
                             tvfin.setText(fin+"");
                    }
                });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my web application, I handle errors with annotations. Everything works fine and I
I have my pickerview set up and everything works fine, but right now I
using jquery ui 1.8 trying autocomplete Everything works apart from that the ui-menu isn't
I compile and run my program in Eclipse and everything works fine, but when
If i browse my site using http://localhost:8080/abc/Login/index.jsf , everything works fine. But if browse
I have simple JSF application. Everything works fine, but not navigation. It behaves like
I'm having some problems with ActiveRecord. Well everything works fine, but it's working sometimes.
In the code below, I am trying to validate a XML. Everything works find
I'm using Struts 1.3.10 to run a site. Everything works well, but I'd like
Everything works as supposed to on the Django development server. In Apache, the django

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.