0

在Griffon in Action书的第 3.6.1 段中有一个 mortageCalc 应用程序的练习。

环境:

  • 赢 7 专业版,64 位
  • IntelliJ IDEA 12.1 版
  • Griffon-1.2.0 JDK 1.6

我有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() 适用于参数类型:(java.util.LinkedHashMap,mortgagecal.MortgageCalView$_run_closure1) 值:[[title:Mortgage Calculator, pack: true, locationByPlatform:true], ...] groovy.lang.MissingMethodException: 没有方法签名:mortgagecal.MortgageCalView.application() 适用于参数类型:(java.util.LinkedHashMap,mortgagecal.MortgageCalView$_run_closure1)值: [[title:Mortgage Calculator, pack:true, locationByPlatform:true], ...] atmortgagecal.MortgageCalView.run(MortgageCalView.groovy:3)

但是,当我在命令提示符下运行时,它工作正常:

cd D:\work\griffon\mortgageCal> 
griffon run-app

所以,我的 IntelliJ 出了点问题……

4

1 回答 1

0

解决了! 它给出错误的原因是因为我试图运行MortgageCalView.groovy。当我运行Griffon:mortgageCal时,它起作用了。:) 换句话说:我必须运行项目,而不是特定的脚本。

于 2013-04-11T10:55:04.090 回答