0

When I put this code between my script. It didn't work. I suppose to put a number in the input, but If I didn't put anything in the INPUT BOX, then the Error Should display.

if( Cost.getText().length() == 0 )

		    {

		     			JOptionPane.showMessageDialog( null, "Cost required",

		    			"Input Required", JOptionPane.WARNING_MESSAGE );

		    			return;

            }
            if( Hours.getText().length() == 0 )

			{

				        JOptionPane.showMessageDialog( null, "Hours required",

				        "Input Required", JOptionPane.WARNING_MESSAGE );

				        return;

            }

Edited by Dasau: n/a

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by kvass
0

I can't see the rest of your code, but it's possible that the string has a null value and thus doesn't have a length of zero. There is a difference between an empty string and a null string. An empty string is like a thread with no beads on it. Adding each character is like adding a bead to the thread and you get a necklace in the end. But the thread is still there in an empty string, and so it has a length of zero. If there is nothing in the input box, it's possible that it's returning null, which means even the thread of the string is not there. Try running the code with the if statement reading: if (Cost.getText() == null)... and see if that solves your problem. You should also usually post your whole code because the problem can be in a place where you least expect it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.