我有以下带有Text
属性的 Profile bean:
import com.google.appengine.api.datastore.Text;
public class Profile {
...
private Text aboutMySelf = null;
public String getAboutMySelf() {
return aboutMySelf.getValue();
}
public void setAboutMySelf(String aboutMySelf) {
this.aboutMySelf = new Text(aboutMySelf);
}
...
}
获取时aboutMySelf
,我有 ff 条件。
if (profile.getAboutMySelf() != null){
...
}
问题是我仍然遇到NPE for lineif (profile.getAboutMySelf() != null)
为什么?如何解决?
堆栈跟踪:
Uncaught exception from servlet
java.lang.NullPointerException
at Profile.getAboutMySelf(Profile.java:263)
at ...(.....java:137)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:45)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)