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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:56:53+00:00 2026-05-18T20:56:53+00:00

I met a small problem when running a Java class that I wrote, though

  • 0

I met a small problem when running a Java class that I wrote, though the design is pretty straightforward. I’ve created a JPanel, and I’ve added four JTextFields onto it and I’ve attached a button to this JPanel, too. Then, I’ve associated an ActionListener to this button being pressed. The code is like:

okButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) 
    {
       if (imageIdField.getText() == "" && 
           captionField.getText() == "" &&
           creditField.getText() == "" &&
           titleField.getText()== "") 
           {
              mediaXML = "";                        
              results.clear();
              results.put("error1", "more");

           } 
           else
           { ....
           }
    }

The strange thing is after I’ve pressed the OK button, and I did input text in those four JTextFields, still it will fall in the IF branch as if I didn’t input any text in any of these four fields.
I’ve been debugging this for a while, but no clue. Could anyone give me some hint like whether .getText() == “” is a valid way for testing no input?

Thanks in advance!

  • 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-18T20:56:53+00:00Added an answer on May 18, 2026 at 8:56 pm

    As has been mentioned, using == is not correct. For readability, try:

    field.getText().isEmpty()
    

    or

    field.getText().trim().isEmpty()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a requirement in my application that I think can be met by
Context: I work at a small software company that has traditionally done research-type work,
i'm trying to make a small project that uses multiple forms (dialogs) for different
(1) I have met several cases where epsilon is added to a non-negative variable
It seems that a lot of small business people have a need for some
I met a problem in Xcode. And my problem was similar to this one:
I've met the same problem as this page: http://www.mail-archive.com/pylons-discuss@googlegroups.com/msg14292.html This is the main content
In R, I met a running error as follows: > png(p3_sa_para.png, 4, 2) >
I've met a new friend. That's a woman and she is a designer. And
I met a problem while using python(2.6) cgi to show a mime data in

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.