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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:24:26+00:00 2026-05-20T20:24:26+00:00

So the form I have written has two fields, a body and a title.

  • 0

So the form I have written has two fields, a body and a title. I am hoping to get the form to throw a toast message if those fields contain no data to prevent the user from saving it to the database. The code should do one of three things. The first being what I am trying to accomplish above. The second is if the ID intent is null, it will create a new entry, and if the ID intent has content, it will update the database entry with the new content. The problem I am having is when the form fields are null, it still saves. It seems to completely skip over my first IF statement and I cant seem to figure out why. I’ve tried using both null and “” for the first IF statement, both separately and together. Help?

  submitBtn.setOnClickListener(new OnClickListener(){
            public void onClick(View v) {
                String titleInsert = titleEdit.getText().toString();
                String bodyInsert = bodyEdit.getText().toString();
                String dateTimeValue = dateTimeTextView.getText().toString();
                if ((titleInsert == null || titleInsert == "") || (bodyInsert == null || bodyInsert == "")){
                    Context context = getApplicationContext();
                    CharSequence text = "Please make sure the Title and Body are both filled before saving";
                    int duration = Toast.LENGTH_SHORT;

                    Toast toast = Toast.makeText(context, text, duration);
                    toast.show();
                }else if(intentRowId == null){
                    try{
                    mDb.open();
                    mDb.createNote(Integer.parseInt(mIntentId), titleInsert, bodyInsert, dateTimeValue);
                    finish();
                    } catch (Exception e) {
                    e.printStackTrace();
                    }
                } else {
                    try{
                        mDb.open();
                        mDb.updateNote(longRowId, titleInsert, bodyInsert);
                        finish();
                    } catch (Exception e){
                        e.printStackTrace();
                        Context context = getApplicationContext();
                        CharSequence text = "SQL Exception Thrown: " + e;
                        int duration = Toast.LENGTH_SHORT;
                        Toast toast = Toast.makeText(context, text, duration);
                        toast.show();
                    }
                }
                }
        });
  • 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-20T20:24:27+00:00Added an answer on May 20, 2026 at 8:24 pm

    Try titleInsert.equals("") etc.

    Additionally, you might want to call titleInsert = titleInsert.trim(); if it is not null, in order to catch blank strings like " ".

    Edit: if you can use Apache commons lang, you could use the class StringUtils which has a isBlank() method, which returns true if the string is null, empty or only contains whitespace.

    Edit2:

    Short explanation on titleInsert.equals(""): == normally checks for the very same object, not for the equality datawise. Thus titleInsert and "" are not necessarily the same object but might be equal (an empty string). Note that you should use equals in almost every case when dealing with (non-null) objects, unless you specifically know you want == instead (which is rare, except for checking obj == null).

    Short example: new Long(1) == 1L is likely to yield false, since new Long(1) creates an object different to the Long object which is used for the literal 1L (also note that I did exclude auto(un)boxing by using 1L). On the other hand, new Long(1).equals(1L) will yield true.

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

Sidebar

Related Questions

I have an input form that is bound to a model. The model has
I have a C# WinForms application that has a WebBrowser control inside of it.
I have written a servlet java program. During the execution of one particular loop
I have written an extension method in csharp for an MVCContrib Html helper and
I'm trying to write a jQuery script (I have never written one before and
I have just written a Word Document creation web application using .NET 3.5 which
I have made a TForm derivative that acts like the drop down part of
I am attempting to detect the file type of a library of files on
I searched around google and stackoverflow, but didnt quite find the right answer. im
This is the PHP code im using in conjunction with jQuery .ajax to create

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.