hola amigos espero que puedan ayudar con esto estoy validando en un textfield que ingresen una direccion de email correcta en el evento focuslost lo de la validacion sale perfecto, ah estoy utilizando BalloonTip, par que aparesca un mensjççaje en el control cuando alguien ingrese un email incorrecto, pero me sale este error cuando quiero cambiar de al dçsiguiente jTextField
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javaapplication1.NewJFrame.jTextField1FocusLost(Ne wJFrame.java:103)
at javaapplication1.NewJFrame.access$000(NewJFrame.ja va:19)
at javaapplication1.NewJFrame$1.focusLost(NewJFrame.j ava:61)
at java.awt.AWTEventMulticaster.focusLost(AWTEventMul ticaster.java:230)
at java.awt.AWTEventMulticaster.focusLost(AWTEventMul ticaster.java:229)
at java.awt.Component.processFocusEvent(Component.jav a:6397)
at java.awt.Component.processEvent(Component.java:626 1)
at java.awt.Container.processEvent(Container.java:222 9)
at java.awt.Component.dispatchEventImpl(Component.jav a:4861)
at java.awt.Container.dispatchEventImpl(Container.jav a:2287)
at java.awt.Component.dispatchEvent(Component.java:46 87)
at java.awt.KeyboardFocusManager.redispatchEvent(Keyb oardFocusManager.java:1893)
at java.awt.DefaultKeyboardFocusManager.typeAheadAsse rtions(DefaultKeyboardFocusManager.java:937)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent (DefaultKeyboardFocusManager.java:611)
at java.awt.Component.dispatchEventImpl(Component.jav a:4731)
at java.awt.Container.dispatchEventImpl(Container.jav a:2287)
at java.awt.Component.dispatchEvent(Component.java:46 87)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:703)
at java.awt.EventQueue.access$000(EventQueue.java:102 )
at java.awt.EventQueue$3.run(EventQueue.java:662)
at java.awt.EventQueue$3.run(EventQueue.java:660)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:676)
at java.awt.EventQueue$4.run(EventQueue.java:674)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 673)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:97)
aui esta el codigo de mi programa
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.java.balloontip.BalloonTip;
este es la funcion que valida
Código:
public boolean validaCorreo(String c){
Pattern p = Pattern.compile("^[a-zA-Z0-9_-]{2,15}@[a-zA-Z0-9_-]{2,15}.[a-zA-Z]{2,4}(.[a-zA-Z]{2,4})?$");
Matcher m = p.matcher(c);
return m.matches();
}
este es el codigo de mi textfield
Código:
private void jTextField1FocusLost(java.awt.event.FocusEvent evt) {
BalloonTip ball=null;
if (!validaCorreo(this.jTextField1.getText())) {
ball=new BalloonTip(this.jTextField1,"Email incorrecto");
ball.setVisible(true);
}
else{
ball.setVisible(false);
}
}