hi

please help me to develop code for JTextField exception handling. i have 10 JTextFields out of which 2 are necessary to fill. if the user left them blank then error message will appear.

try{
text1=a.getText();
text2=b.getText();
while(a!= null && b!=null);}

catch(Exception e){
System.out.println("Please write some text" +e.getMessage());}

this code is not working. the program is not responding after this code. why??
please help.

the program is not responding

Look at the while loop coding. Check the ending ;

What do you want to happen with the loop you have coded?

I don't see any comments in the code describing what it is supposed to do.
So I can only assume that it is doing what you want.

try{
text1=a.getText(); //text field that is necessary to fill
text2=b.getText(); //text field that is necessary to fill
while(a!= null && b!=null); 
//check for condition whether a and b are null or not. 

} 
catch(Exception e)
{System.out.println("Please write some text" +e.getMessage());
// if JTextFields (a and b) are null an error message will appear
}

please correct it or guide me how to do it?

Look at the while loop coding. Check the ending ;

The ; ends the while statement giving it an empty statement.

What do you want to do in the while loop?
Your code does nothing.

I have removed ; this. But the same problem.

i want to check whether JTextField is empty or not. I have tried it from if else too but dont get the desired results. Please guide me.

Have you looked at the API doc for the JTextField class?
What method(s) look useful for testing what is in the JTextField?
Also look in the class that JTextField extends.
For example if you get the contents of the JTF and it returns a 0 length String, would that be what you want to know?

Thanks for your reply.

can you give me an example.

You can determine a's length using:

a.length();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.