You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Taught by S&M <qa...@gmail.com> on 2014/10/06 04:57:53 UTC

Re: how to handle null pointer exception while submit button

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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: how to handle null pointer exception while submit button

Posted by Paul Bors <pa...@bors.ws>.
Must be the wrong mailing list, ignore :)

On Sun, Oct 5, 2014 at 11:15 PM, Warren Bell <wa...@clarksnutrition.com>
wrote:

> OK, a little confused, AWT, Applet ? Is Wicket up to something I haven’t
> heard about ?
>
> Warren
>
> On Oct 5, 2014, at 7:57 PM, Taught by S&M <qa...@gmail.com>
> wrote:
>
> > 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-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
> > --
> > This email was Virus checked by Clark's Nutrition's Astaro Security
> Gateway.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: how to handle null pointer exception while submit button

Posted by Warren Bell <wa...@clarksnutrition.com>.
OK, a little confused, AWT, Applet ? Is Wicket up to something I haven’t heard about ?

Warren

On Oct 5, 2014, at 7:57 PM, Taught by S&M <qa...@gmail.com> wrote:

> 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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> -- 
> This email was Virus checked by Clark's Nutrition's Astaro Security Gateway.


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