gpt4 book ai didi

exception - Grails 奇怪的属性异常

转载 作者:行者123 更新时间:2023-12-03 08:17:44 25 4
gpt4 key购买 nike

希望我没有在这里放太多代码..我有一个我认为很奇怪的问题..我有 2 个类..

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
}

我有一些代码可以通过执行从当前记录生成历史记录

cardHistoryInstance.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} .."
}

所以基本上我可以单独访问每个属性,但是通过 properties 关键字访问是给我一个 npe ..任何人都可以对此有所了解吗?Grails 1.3.6 ..

谢谢

最佳答案

不,您应该将 Seat 的属性称为 activeCard,而不是 card:

try{
def cardHistoryEntry = new CardHistory();
println cardHistoryEntry.properties
println "properties okay .."

assert seat
println "Seat okay ..."

assert seat.activeCard
println "Card okay ..."

println seat.activeCard.dateCreated
println "Date okay ..."

println seat.activeCard.customerNumber
println "customer number okay .. "

println "Seems okay .."

println seat.activeCard.properties
println "Don't get to here"
}
catch(e)
{
println "OOps .. An error occurred ${e} .."
}

关于exception - Grails 奇怪的属性异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8496752/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com