1
我有這些類:堅持雙向關係ormlite
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: ERROR/AndroidRuntime(802): java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.project/br.com.project.DaoTestActivity}: java.lang.NullPointerException
那麼NPE發生了什麼?你有沒有試過調試你的代碼來找出那行上哪些對象是空的?沒有足夠的信息讓任何人弄清楚你試圖訪問空指針的代碼在哪裏。 – Gray 2012-04-24 14:00:41
我沒找到線。我從AllegationItem中刪除了ForeignCollection,並嘗試創建一個AllegationItem,並得到這個錯誤:「INFO/Database(1024):sqlite returned:error code = 1,msg = near」)「syntax」 我無法理解.. 。AllegationItem只有字段Id。 – Munir 2012-04-24 14:33:54
對不起,我們提供的幫助信息太少。 – Gray 2012-04-24 14:36:28