Author
java.lang.NullPointerException
vineet walia
Ranch Hand
Joined: Feb 16, 2008
Posts: 138
i am new to struts 2.0 please help
index.jsp
client.jsp
error.jsp
clientaction.java
struts.xml
vineet walia
Ranch Hand
Joined: Feb 16, 2008
Posts: 138
web.xml
vineet walia
Ranch Hand
Joined: Feb 16, 2008
Posts: 138
index.jsp page is working but when i submit form it is giving these error
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
clientaction.execute(clientaction.java:27)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3786
I think your problem is here:
If getname() returns null , the first part of that expression will throw a NullPointerException . The test for null needs to come before calling any methods of the object.
(As an aside, shouldn't it be getN ame(), setN ame(), etc to follow the Java Beans convention?)
vineet walia
Ranch Hand
Joined: Feb 16, 2008
Posts: 138
Matthew Brown wrote: I think your problem is here:
If
getname() returns
null , the first part of that expression will throw a
NullPointerException . The test for null needs to come before calling any methods of the object.
(As an aside, shouldn't it be get
N ame(), set
N ame(), etc to follow the Java Beans convention?)
suggest solution?
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3786
I just did! The test for null needs to come first. E.g:
vineet walia
Ranch Hand
Joined: Feb 16, 2008
Posts: 138
Matthew Brown wrote: I just did! The test for null needs to come first. E.g:
it is giving same problem
are you sure it is working on your side ?
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
posted Jun 24, 2010 05:35:29
0
1) Your getters and setters don't follow JavaBean conventions; they should be similar to "getName()" and "setName()" etc.
2) The result values in your struts.xml file are wrong; they should be lower case--at least if you're going to use Action.SUCCESS etc. in your code.
3) Why are you doing validation in the execute() method? There's a validate() method in ActionSupport for a reason.
4) client.jsp has at least two misspelled tags and won't compile, and I have no idea why you're importing a Java class.
vineet walia
Ranch Hand
Joined: Feb 16, 2008
Posts: 138
i just start reading struts so dnt know much about it.
i am reading from struts black book this example is from that book
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
posted Jun 24, 2010 05:50:27
0
Okay, well, it's not a very good book then, if that's what it's telling you to do. Do what I said instead.
subject: java.lang.NullPointerException