nullPointer
我在 getter 方法上有问题。
这是代码:
public String getTitle()
{
if(!title.isEmpty())
return title;
else
return "foo";
}
当我将其更改为普通吸气剂时,它可以完美运行。
public String getTitle()
{
return title;
}
诀窍在哪里?有反射技巧吗?
更新问题不是空检查,而是执行getter而不调用它
堆栈跟踪
org.codehaus.jackson.map.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: java.util.ArrayList[0]- >si.mikropis.webkiosk.model.vao.wine.Wine["title"])
Caused by: java.lang.NullPointerException
at si.mikropis.webkiosk.model.vao.base.BaseModel.getTitle(BaseModel.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.get(BeanPropertyWriter.java:483)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:418)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
... 32 more