我有这些课程:
public class AllegationContent {
@DatabaseField(generatedId = true)
protected long id;
@DatabaseField(canBeNull = true, foreign = true)
private AllegationItem allegationItem;
@DatabaseField()
protected String content;
...
}
和:
public class AllegationItem {
@DatabaseField(generatedId = true)
protected long id;
@ForeignCollectionField(eager = false)
protected ForeignCollection<AllegationContent> allegationContent;
...
}
我怎样才能坚持两者?我正在尝试这个:
allegationContentDao = getAllegationContentDao();
AllegationContent allegationContent = new AllegationContent();
allegationContent.setContent("allegation content");
allegationContentDao.create(allegationContent);
allegationItemDao = getAllegationItemDao();
AllegationItem allegationItem = new AllegationItem();
AllegationContent allegationContent2 = allegationContentDao.queryForSameId(allegationContent); //is that wrong?
allegationItem.getAllegationContent().add(allegationContent2);
allegationItemDao.create(allegationItem);
但我收到了这个错误:
04-24 10:41:57.128: 错误/AndroidRuntime(802): java.lang.RuntimeException: 无法启动活动 ComponentInfo{br.com.project/br.com.project.DaoTestActivity}: java.lang.NullPointerException