This code will help to handle exceptions when there is a single TextField:

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

/*
<applet code="throwsDemo.class" height=250 width=300>
</applet>
*/

class FieldZeroException extends Exception
{
        FieldZeroException()
        {
        }
        
        public String toString()
        {
        return "Text field is empty.";
        }
}

public class throwsDemo extends Applet implements ActionListener
{
Button b1;
TextField tf1,tf2;
Label l1,l2;

        public void init()
        {
        setLayout(new FlowLayout(FlowLayout.LEFT));
        l1=new Label("NULL");
        l1.setForeground(Color.RED);
        l2=new Label();
        l2.setForeground(Color.GREEN);
        tf1=new TextField(10);
        b1=new Button("Check");
        add(tf1);
        add(b1);
        add(l1);
        add(l2);
        b1.addActionListener(this);
        }
        
        public void actionPerformed(ActionEvent ae)
        {
                if(ae.getSource()==b1)
                {
                String str1=tf1.getText();
                int i=str1.length();
                        try
                        {
                                if(i==0)
                                {
                                throw new FieldZeroException();
                                }
                                else
                                {
                                l1.setText("Success");
                                }
                        }
                        catch(FieldZeroException fze)
                        {
                        l1.setText(fze.toString());
                        }
                }
        }
}

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/how-to-handle-null-pointer-exception-while-submit-button-tp4666392p4667826.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to