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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:52:23+00:00 2026-06-11T17:52:23+00:00

I have 2 edittext fields where it needs the item name (String) and the

  • 0

I have 2 edittext fields where it needs the item name (String) and the quantity (Integer). If user enters nothing on both fields or if even just one field is empty, I want to show a toast saying “please enter item” or “please enter quantity”. It creates and error. Here is the snippet below:

 public void onClick(DialogInterface dialog, int id) {

                        String item = itemET.getText().toString();
                        int quantity = Integer.parseInt(quantityET.getText().toString());
                        if(itemET.equals("")){
                            Toast t =Toast.makeText(GroceryList.this, "Please enter item", 5000);
                            t.show();   
                            }
                            if(quantityET.equals("")){
                            Toast t =Toast.makeText(GroceryList.this, "Please enter quantity or enter 0 if none", 5000);
                            t.show();
                            }

And here is the error in logcat:

09-19 10:01:51.766: E/AndroidRuntime(527): FATAL EXCEPTION: main
09-19 10:01:51.766: E/AndroidRuntime(527): java.lang.NumberFormatException: unable to parse '' as integer
09-19 10:01:51.766: E/AndroidRuntime(527):  at java.lang.Integer.parseInt(Integer.java:362)
09-19 10:01:51.766: E/AndroidRuntime(527):  at java.lang.Integer.parseInt(Integer.java:332)
09-19 10:01:51.766: E/AndroidRuntime(527):  at com.mexican.recipes.GroceryList$1$1.onClick(GroceryList.java:60)
09-19 10:01:51.766: E/AndroidRuntime(527):  at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:159)
09-19 10:01:51.766: E/AndroidRuntime(527):  at android.os.Handler.dispatchMessage(Handler.java:99)
 09-19 10:01:51.766: E/AndroidRuntime(527):     at android.os.Looper.loop(Looper.java:123)
 09-19 10:01:51.766: E/AndroidRuntime(527):     at android.app.ActivityThread.main(ActivityThread.java:3683)
 09-19 10:01:51.766: E/AndroidRuntime(527):     at java.lang.reflect.Method.invokeNative(Native Method)
 09-19 10:01:51.766: E/AndroidRuntime(527):     at java.lang.reflect.Method.invoke(Method.java:507)
 09-19 10:01:51.766: E/AndroidRuntime(527):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
 09-19 10:01:51.766: E/AndroidRuntime(527):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
 09-19 10:01:51.766: E/AndroidRuntime(527):     at dalvik.system.NativeStart.main(Native Method)
  • 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-11T17:52:24+00:00Added an answer on June 11, 2026 at 5:52 pm

    There’s two seperate problems in this code: calling parseInt on an empty string is going to raise an exception (the error you’re seeing), and you’re doing a .equals comparison on the EditText object itself, not on the string contained inside. Do the following:

    public void onClick(DialogInterface dialog, int id) {
    
       String itemString = itemET.getText().toString();
       String quantityString = quantityET.getText().toString();
       int quantity;
    
       if(itemString.equals(""))
       {
          Toast t =Toast.makeText(GroceryList.this, "Please enter item", 5000);
          t.show();   
       }
    
       if(quantityString.equals("")){
          Toast t =Toast.makeText(GroceryList.this, "Please enter quantity or enter 0 if none", 5000);
          t.show();
       }
       else {
          quantity = Integer.parseInt(quantityString);
       }
    }
    

    This will still crash if you supply something which isn’t a number (for example, if you typed ‘a’ into the box), but it should be able to handle nothing being entered.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three Edittext fields ed1,ed2,ed3. When user clicked the ed2 /ed3 I have
All- I have an EditText field where the user enters a currency value (eg.
I have an activity that contains several user editable items (an EditText field, RatingBar,
I have a setup view where the user can enter their name and email
I have an Activity with some EditText fields and some buttons as a convenience
i have a small form with four EditText fields in which second EditText is
I have 3 EditText fields set up in a similar way to as follows:
I have 6 EditText fields in an xml.. on Button click I need to
I have created two EditText fields and a single submit button in Android using
I am trying to have more than one Edittext fields to send via a

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.