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

  • Home
  • SEARCH
  • 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 6771975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:29:43+00:00 2026-05-26T15:29:43+00:00

I have a few edittexts and a button. On click of the button, I

  • 0

I have a few edittexts and a button.
On click of the button, I do some action with edittext values. I wish to check if all edittexts are filled in before I proceed. So I use code in onclick listener

if("".equals(etLandSize.getText().toString()) || null == etLandSize.getText().toString())
    {
        Toast toast = Toast.makeText(context, text, duration);
        toast.show();

        return;
    }

//followed by some actions.

If the above condition goes true, I expect the method to return without doing anything by using a ‘return’.

My problem is that even when the condition is going true, the lines following this condition are executing and I see the NPEs from log since the fields are empty.

If I comment all the lines after this condition, only then I see the expected Toast and my Activity remains there, which is normal behavior.

Am I doing something wrong here?

An alternate is that i can put the code following condition in else{} block. But just wondering why I cannot use a return. Apologies if I’m not realising some basic mistake.

  • 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-05-26T15:29:44+00:00Added an answer on May 26, 2026 at 3:29 pm

    Your condition looks weird.

    I’m pretty sure null == etLandSize.getText().toString() will never be true, and I would use

    etLandSize.getText().length() == 0
    

    instead of "".equals(etLandSize.getText().toString(), since using "" to avoid comparisson with null is not usefull here – toString() cannot return null.

    So try this:

    if (etLandSize.getText().length() == 0)
    {
        Toast toast = Toast.makeText(context, text, duration);
        toast.show();
    
        return;
    }
    

    BTW: if your return; is within try {} block, then part of the coded located in finally{} block will be run after it.

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

Sidebar

Related Questions

I have few pairs of button & check box like on my pages (the
I have few buttons of which each button is assigned a class with a
I have few Vaadin tabs one of them is displaying an table and some
I have few questions. First of all does code below violates law of Demeter?
I have few td in my code. The scenario is when I click on
I have a few edittext within a listview. i have a generic focuslistener on
I have an Android application with a few edittext boxes. The issue I am
I am learning how to create UI elements. I have created a few EditText
I have one spinner in which few values are there from strings.xml and I
Hi I have an LinearLayout inside FrameLayout , the linear layout contains few edittext

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.