Google App Engine文本的NullPointerException

时间:2013-05-13 02:49:00

标签: java google-app-engine struts2 nullpointerexception

我有以下具有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){
    ...
}

问题是我仍遇到行if (profile.getAboutMySelf() != null)的NPE 为什么?如何解决?

堆栈跟踪:

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)

0 个答案:

没有答案