3
希望我沒有把太多的代碼在這裏..我有什麼,我認爲一個奇怪的問題..我有2班..Grails的奇特性質異常
class Card {
String customerNumber
String memberId
String cardNumber
String issueNumber
Boolean active = true
// Audit info ..
Date dateCreated
String createdBy
Integer uniqId
}
class CardHistory extends Card {
static constraints = {
note(nullable: true, size:1..500)
}
// History note
String note
// Audit info ..
Date originalDateCreated
String originalCreatedBy
Integer originalUniqId
}
和另一..
class Seat {
...
Card activeCard
}
我有一些代碼,做
產生從當前歷史記錄0cardHistoryInstance.properties = seat.card.properties
但它拋出一個NullPointerException
..
所以我寫了這個測試吧..
def seat = Seat.get(1)
try{
def cardHistoryEntry = new CardHistory();
println cardHistoryEntry.properties
println "properties okay .."
assert seat
println "Seat okay ..."
assert seat.card
println "Card okay ..."
println seat.card.dateCreated
println "Date okay ..."
.... and each of the other properties
println seat.card.customerNumber
println "customer number okay .. "
println "Seems okay .."
println seat.card.properties <---- Blows up with NPE here ..
println "Don't get to here"
}
catch(e)
{
println "OOps .. An error occurred ${e} .."
}
所以基本上我可以在每個單獨的屬性,但通過屬性關鍵字訪問是給我一個ê..任何人都可以擺脫這個光? Grails的1.3.6 ..
感謝
後從異常堆棧跟蹤,你能看到這行的原因NPE。 – 2011-12-13 22:27:37
多數民衆贊成在什麼讓我困惑..堆棧跟蹤指向我突出顯示的行.. println seat.card.properties ..它給了我一個猿,但我可以打印每個單獨的屬性! – user566311 2011-12-13 23:59:35