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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:58:54+00:00 2026-06-01T01:58:54+00:00

I have a button and an edittext. The user enters a number and then

  • 0

I have a button and an edittext. The user enters a number and then clicks the button. Something then happens with that number.

However i get an error when the edittext is blank. How do i fix this? My code below is my attempt..but it doesn’t work as i get the following error and my app closes:

E/AndroidRuntime(324): java.lang.NumberFormatException: unable to parse ” as integer

public void onClick(View arg0) {
    // TODO Auto-generated method stub
    switch (arg0.getId()) {
    case R.id.bBankDeposit:
        deposit();
        break;
    case R.id.bBankWithdraw:
        withdraw();
        break;
    }
}

public void deposit() {
    String d = etDepositAmount.getText().toString();
    Integer depositAmount = Integer.valueOf(d);

    if (depositAmount > playerCash | depositAmount <= 0
            | etDepositAmount.getText().toString() == "") {
        new AlertDialog.Builder(this).setTitle("Wait")
                .setMessage("Please enter a valid deposit value.")
                .setPositiveButton("OK", null).show();
        etDepositAmount.setText("");
    } else {
        int newBankBalance = playerBalance + depositAmount;
        playerBalance = newBankBalance;
        playerCash = (playerCash - depositAmount);

        bankBalance.setText("Bank Balance: $" + playerBalance);
        cash.setText("Cash in hand: $" + playerCash);
        etDepositAmount.setText("");

        Player stats = new Player(this);
        stats.open();
        stats.bankDeposit(playerId, playerCash, playerBalance);
        stats.close();
    }
}

}

  • 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-01T01:58:55+00:00Added an answer on June 1, 2026 at 1:58 am

    The idea behind your solution is correct, you just have some minor syntax errors.

    When you do Integer.valueOf(string) you need to handle a number format exception. It’s just Java’s way of letting you know it can reliably return an Integer for the given string.

    | is a bitwise OR operation. Presumably you want ||, which compares using boolean logic. Secondly, when comparing strings you want to compare by value, not by reference. == compares by reference, while someString.equals(someOtherString) will actually check the contents of the string. You really don’t need to do that though because you’ve already parsed it into an Integer.

    With those fixes you’ll figure out if the input is incorrect and display an alert if necessary.

    So – the full solution is ….

    public void deposit() {
        String d = etDepositAmount.getText().toString();
        Integer depositAmount = 0;
        try
        {
           depositAmount = Integer.valueOf(d);
        }
        catch(NumberFormatException ex)
        {
           // Uh oh! Bad input!
        }
    
        if (depositAmount > playerCash || depositAmount <= 0) 
        {
            new AlertDialog.Builder(this).setTitle("Wait")
                    .setMessage("Please enter a valid deposit value.")
                    .setPositiveButton("OK", null).show();
            etDepositAmount.setText("");
        } else {
            int newBankBalance = playerBalance + depositAmount;
            playerBalance = newBankBalance;
            playerCash = (playerCash - depositAmount);
    
            bankBalance.setText("Bank Balance: $" + playerBalance);
            cash.setText("Cash in hand: $" + playerCash);
            etDepositAmount.setText("");
    
            Player stats = new Player(this);
            stats.open();
            stats.bankDeposit(playerId, playerCash, playerBalance);
            stats.close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an EditText (that the user can type numbers in), so when the
In my application I have several EditText. When the User clicks on the first,
I have an XML layout file that contains an EditText and a Button .
I have a edittext which the user enters some text into Once they press
I have implemented activity with edittext and button: After user entered a password and
I have a EditText box so a user can input names and then click
I have 4 text boxes and when the user clicks a button i wish
I have a list view, editText and button. editText and button are my footer
I have an EditText and a Button set next to each other on the
friends, i have a EditText on simple activity with a button. when every i

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.