我正在使用 Flex+java(Spring+hibernate)...
Java端...
public enum WeekdayType {
MONDAY(Calendar.MONDAY), TUESDAY(Calendar.TUESDAY), WEDNESDAY(
Calendar.WEDNESDAY), THURSDAY(Calendar.THURSDAY), FRIDAY(
Calendar.FRIDAY), SATURDAY(Calendar.SATURDAY), SUNDAY(
Calendar.SUNDAY);
private int day;
private WeekdayType(int day) {
this.day = day;
}
}
我正在使用的休眠 Bean 类..TimetableVO.java
@Column(name="REPEAT_DAYS")
private String repeatDays;
@Transient
public List<WeekdayType> getRepeatDaysEnumList(){
List<WeekdayType> list = new ArrayList<WeekdayType>();
for(String str : this.repeatDays.split(",")){
list.add(WeekdayType.valueOf(str));
}
return list;
}
@Transient
public void setRepeatDaysEnumList(List<WeekdayType> repeatDays){
StringBuilder sb = new StringBuilder();
for(WeekdayType weekdayType : repeatDays){
sb.append(weekdayType.name());
sb.append(",");
}
this.repeatDays = sb.substring(0, sb.length()-1);
}
在 Flex 方面...
private var timetableVO:TimetableVO = new TimetableVO();
timetableVO.repeatDays = selectedDays.substr(0, selectedDays.length-1);
private var selectedDays:String = null;
protected function selectRepeatedDays(event:MouseEvent):void
{
selectedDays = new String();
if(MON.selected==true)
{
selectedDays += "MONDAY,";
}
if(TUE.selected==true)
{
selectedDays += "TUESDAY,";
}
}
只是我在 repeateDays 中添加值但它给NullPointer Exception
Exception:Property 'repeatDaysEnumList' threw exception; nested exception is java.lang.NullPointerException.......
Caused by: java.lang.NullPointerException
at com.sits.ec.valueObjects.TimetableVO.setRepeatDaysEnumList(TimetableVO.java:64)
我没有创建repeatDaysEnumList,但是由于Setter和Getter,Hibernate会这样做,那么这个Null值是如何来的......