在Griffon in Action一书的第3.6.1段中有一个使用mortageCalc应用的练习。
环境:
我有 MortgageCalView :
package mortgagecal
application(title:'Mortgage Calculator', pack:true, locationByPlatform:true)
{
panel(border: emptyBorder(6)) {
gridLayout(rows:4, columns:2, hgap:6, vgap:6)
label('Principal:')
textField(text: bind(target:model, 'principal',
value:'$200,000',
validator: model.validatePrincipal,
converter: model.convertPrincipal))
label('Interest Rate:')
textField(text: bind(target:model, 'monthlyRate',
value:'6.5%',
validator: model.validateRate,
converter: model.convertRate))
label('Term:')
textField(text: bind(target:model, 'months',
value:'30',
validator: model.validateTerm,
converter: model.convertTerm))
label('Monthly Payment (P&I):')
textField(editable:false,
text: bind(source: model, sourceProperty: 'payment',
sourceEvent: 'propertyChange',
converter: model.convertPayment))
}
}
和 MortgageCalModel :
package mortgagecal
import groovy.beans.Bindable
import java.text.NumberFormat
import java.text.DecimalFormat
@Bindable
class MortgageCalModel {
float principal
float monthlyRate
float months
float getPayment() {
return principal * monthlyRate /
(1-Math.pow(1/(1+monthlyRate),months))
}
private currencyFormat = NumberFormat.currencyInstance
private percentFormat = new DecimalFormat('0.00%')
def validatePrincipal = {
try {
float principal = currencyFormat.parse(it)
return principal > 0
} catch (Exception e) {
return false
}
}
def convertPrincipal = currencyFormat.&parse
def validateRate = {
try {
float rate = percentFormat.parse(it)
return rate > 0 && rate < 0.30
} catch (Exception e) {
return false
}
}
def convertRate = {
return percentFormat.parse(it) / 12
}
def validateTerm = {
try {
def term = Float.parseFloat(it)
return term > 0 && term < 100
} catch (Exception e) {
return false
}
}
def convertTerm = {
return Float.parseFloat(it) * 12
}
def convertPayment = {
return currencyFormat.format(it)
}
}
运行时,我看到错误:
抓住:groovy.lang.MissingMethodException:没有方法签名: mortgagecal.MortgageCalView.application()适用于参数 types:(java.util.LinkedHashMap, mortgagecal.MortgageCalView $ _run_closure1)值:[[title:Mortgage 计算器,包:true,locationByPlatform:true],...] groovy.lang.MissingMethodException:没有方法签名: mortgagecal.MortgageCalView.application()适用于参数 types:(java.util.LinkedHashMap, mortgagecal.MortgageCalView $ _run_closure1)值:[[title:Mortgage 计算器,包:true,locationByPlatform:true],...] at mortgagecal.MortgageCalView.run(MortgageCalView.groovy:3)
但是,当我在命令提示符下运行时,它运行正常:
cd D:\work\griffon\mortgageCal>
griffon run-app
所以,我的IntelliJ出现了问题......
答案 0 :(得分:0)
解决! 它之所以出错,是因为我试图运行 MortgageCalView.groovy 。 当我运行 Griffon:mortgageCal 时,它有效。 :)换句话说:我必须运行项目,而不是特定的脚本。