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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:18:04+00:00 2026-06-17T15:18:04+00:00

I have 2 edittext fields empty and i want to when i type numbers

  • 0

I have 2 edittext fields empty and i want to when i type numbers inside the two fields a 3rd textview will automatically get the division of the 2 above edittexts. So no buttons to calculate that etc.

The thing is when i enter one number on any field the app gets force closed. Here is my code and the logcat:

    amount.addTextChangedListener(new TextWatcher() {

        public void afterTextChanged(Editable arg0) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            AddFuelActivity.this.updateValue();
        }

    });

    litres.addTextChangedListener(new TextWatcher() {

        public void afterTextChanged(Editable arg0) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            AddFuelActivity.this.updateValue();
        }

    });


protected void updateValue() {
    int amountInt = Integer.parseInt(amount.getText().toString());
    int litresInt = Integer.parseInt(litres.getText().toString());
    float priceFuelAuto = 0;
    priceFuelAuto = amountInt / litresInt;
    fuelPrice.setText("€ " + priceFuelAuto);
}

logcat errors: i think these are the important ones.

01-22 13:23:21.650: E/AndroidRuntime(671): java.lang.NumberFormatException: Invalid int: ""
01-22 13:23:21.650: E/AndroidRuntime(671):  at java.lang.Integer.invalidInt(Integer.java:138)
01-22 13:23:21.650: E/AndroidRuntime(671):  at java.lang.Integer.parseInt(Integer.java:359)
01-22 13:23:21.650: E/AndroidRuntime(671):  at java.lang.Integer.parseInt(Integer.java:332)
01-22 13:23:21.650: E/AndroidRuntime(671):  atcom.example.mycarfuel.AddFuelActivity.updateValue(AddFuelActivity.java:155)
01-22 13:23:21.650: E/AndroidRuntime(671):  atcom.example.mycarfuel.AddFuelActivity$2.onTextChanged(AddFuelActivity.java:67)

I fixed my code. Here is what i did:

    public void onTextChanged(CharSequence s, int start, int before,
            int count) {
        if (litres.length() > 0) {
            AddFuelActivity.this.updateValue();
        }
    }

and

    int amountInt = 0;
    int litresInt = 0;
    try {
        amountInt = Integer.parseInt(amount.getText().toString());
        litresInt = Integer.parseInt(litres.getText().toString());
    } catch (NumberFormatException e) {
        litresInt = 0;
        amountInt = 0;
    }
    if(amountInt !=0 && litresInt != 0){
        float priceFuelAuto = 0;
        priceFuelAuto = amountInt / litresInt;
        fuelPrice.setText("€ " + priceFuelAuto);
    }

thank you for your replies people

  • 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-17T15:18:06+00:00Added an answer on June 17, 2026 at 3:18 pm
    @Override
            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {
                // TODO Auto-generated method stub
                if(edittext1.length()!=0){
                updateValue() 
    
                }
                else{
                    edittext2.setText("");
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have users entering numbers into an EditText fields, but what I would like
I have two fields that i want to calculate. The program works fine if
I am trying to add two numbers together from EditText fields. So far I
I have created two EditText fields and a single submit button in Android using
In one of my views, I have three EditText fields. The first two are
I have EditText in my XML as <!-- Inside RelativeLayout --> <EditText android:id=@+id/edtEmail android:layout_width=match_parent
I have an EditText and I want to attach to it a KeyListener that
I have an EditText input that I would like to only allow numbers 1
I have an EditText, which generally shows parallel to the screen X-axis. I want
i have a small form with four EditText fields in which second EditText is

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.