You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by armandoxxx <ar...@dropchop.com> on 2011/07/28 16:07:14 UTC

NullPointerException and don't know why ...

Hi guys got a problem with NPE 

I'm having using Kaptcha for drawing captcha ..  



public class CaptchaImage extends NonCachingImage {
	 
	private static final long serialVersionUID = 1667766853896645923L;

	private transient DefaultKaptcha captchaProducer	= new DefaultKaptcha();

	// private DefaultKaptcha captchaProducer;
	public CaptchaImage(String id) {
		super(id);
		
		captchaProducer.setConfig(new Config(new Properties()));
		
		setImageResource(new DynamicImageResource() {
			
			private static final long serialVersionUID = -3696927797622999885L;
			
			
			public byte[] getImageData() {
				ByteArrayOutputStream os = new ByteArrayOutputStream();
				
				// write the data out
				ImageIO.setUseCache(false);
				
				try {
					BufferedImage bi = getImageCaptchaService();
					ImageIO.write(bi, "jpg", os);
					return os.toByteArray();
				} catch (Exception e) {
					throw new RuntimeException(e);
				}
			};
			
			
			private BufferedImage getImageCaptchaService() {
				Request request = RequestCycle.get().getRequest();
				HttpServletRequest httpRequest = ((WebRequest)
request).getHttpServletRequest();
				String capText = captchaProducer.createText();
				// store the text in the session
				httpRequest.getSession().setAttribute(Constants.KAPTCHA_SESSION_KEY,
capText);
				// create the image with the text
				BufferedImage bi = captchaProducer.createImage(capText);
				return bi;
			}
		});
	}
}



the problem is that I'm getting NPE on line: 

String capText = captchaProducer.createText();


and I can't figure out why ... 

can anybody help please ? 

Regards 

Armando


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/NullPointerException-and-don-t-know-why-tp3701404p3701404.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: NullPointerException and don't know why ...

Posted by armandoxxx <ar...@dropchop.com>.
thank you ! 

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/NullPointerException-and-don-t-know-why-tp3701404p3701481.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: NullPointerException and don't know why ...

Posted by Martin Grigorov <mg...@apache.org>.
Because it is transient and after deserialization it will be null.

On Thu, Jul 28, 2011 at 5:07 PM, armandoxxx <ar...@dropchop.com> wrote:
> Hi guys got a problem with NPE
>
> I'm having using Kaptcha for drawing captcha ..
>
>
>
> public class CaptchaImage extends NonCachingImage {
>
>        private static final long serialVersionUID = 1667766853896645923L;
>
>        private transient DefaultKaptcha captchaProducer        = new DefaultKaptcha();
>
>        // private DefaultKaptcha captchaProducer;
>        public CaptchaImage(String id) {
>                super(id);
>
>                captchaProducer.setConfig(new Config(new Properties()));
>
>                setImageResource(new DynamicImageResource() {
>
>                        private static final long serialVersionUID = -3696927797622999885L;
>
>
>                        public byte[] getImageData() {
>                                ByteArrayOutputStream os = new ByteArrayOutputStream();
>
>                                // write the data out
>                                ImageIO.setUseCache(false);
>
>                                try {
>                                        BufferedImage bi = getImageCaptchaService();
>                                        ImageIO.write(bi, "jpg", os);
>                                        return os.toByteArray();
>                                } catch (Exception e) {
>                                        throw new RuntimeException(e);
>                                }
>                        };
>
>
>                        private BufferedImage getImageCaptchaService() {
>                                Request request = RequestCycle.get().getRequest();
>                                HttpServletRequest httpRequest = ((WebRequest)
> request).getHttpServletRequest();
>                                String capText = captchaProducer.createText();
>                                // store the text in the session
>                                httpRequest.getSession().setAttribute(Constants.KAPTCHA_SESSION_KEY,
> capText);
>                                // create the image with the text
>                                BufferedImage bi = captchaProducer.createImage(capText);
>                                return bi;
>                        }
>                });
>        }
> }
>
>
>
> the problem is that I'm getting NPE on line:
>
> String capText = captchaProducer.createText();
>
>
> and I can't figure out why ...
>
> can anybody help please ?
>
> Regards
>
> Armando
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/NullPointerException-and-don-t-know-why-tp3701404p3701404.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
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com