Xquery:There is more than one method matching the function 异常处理
来源:互联网 发布:90后童年游戏 知乎 编辑:程序博客网 时间:2024/06/05 02:37
本人系统使用了saxon9作为xquery脚本解析工具,在对数字进行相加的时候,由于浮点型数字容易出现精度丢失,因此,在脚本中定义了命名空间,准备引入java.util.Math中的round函数使用保留小数位的方法来对浮点数进行转换,脚本片段如下
declare namespace math = 'java:java.lang.Math';<body><table class="fb_result" width="100%"><tr class="fb_result_head"><th colspan="100">余额信息</th></tr><tr class="fb_result_head"><td width="2%"></td><td width="13%">ID</td><td width="17%">名称</td><td width="8%">总额(元)</td><td width="8%">已用(元)</td><td width="8%">可用(元)</td></tr>{for $a in //Record return <tr class="fb_result_content"> <td><input type="radio" name="radiobutton" value="radiobutton" checked="checked" onclick="saveId({$a/Id})"/></td><td>{$a/Id}</td><td>{$a/Name}</td><td>{$a/All}</td><td>{xs:double(math:round(($a/All/number() - $a/Available/number())*1000) div 1000.00)}</td> <td>{$a/Available}</td> </tr>}{let $sum1 :=sum(//Record/Available/number())let $sum2 :=sum(//Record/All/number())return<tr class="fb_result_content" style="font-weight:bold;"> <td align="left" colspan="3">小计</td><td>{$sum2}</td><td>{xs:double(math:round(($sum2 - $sum1)*1000) div 1000.00)}</td><td>{$sum1}</td><td colspan="4"></td></tr>}</table></body>
但是,在执行脚本解析的时候,系统报错如下
Caused by: net.sf.saxon.trans.XPathException: There is more than one method matching the function call math:round, and there is insufficient type information to determine which one should be usedat net.sf.saxon.functions.JavaExtensionLibrary$UnresolvedExtensionFunction.typeCheck(JavaExtensionLibrary.java:901)at net.sf.saxon.expr.ExpressionVisitor.typeCheck(ExpressionVisitor.java:181)at net.sf.saxon.expr.ArithmeticExpression.typeCheck(ArithmeticExpression.java:78)at net.sf.saxon.expr.ExpressionVisitor.typeCheck(ExpressionVisitor.java:181)at net.sf.saxon.instruct.ParentNodeConstructor.typeCheck(ParentNodeConstructor.java:165)at net.sf.saxon.expr.ExpressionVisitor.typeCheck(ExpressionVisitor.java:181)at net.sf.saxon.instruct.Block.typeCheck(Block.java:447)at net.sf.saxon.expr.ExpressionVisitor.typeCheck(ExpressionVisitor.java:181)at net.sf.saxon.instruct.ParentNodeConstructor.typeCheck(ParentNodeConstructor.java:165)at net.sf.saxon.expr.ExpressionVisitor.typeCheck(ExpressionVisitor.java:181)at net.sf.saxon.expr.LetExpression.typeCheck(LetExpression.java:110)at net.sf.saxon.expr.ExpressionVisitor.typeCheck(ExpressionVisitor.java:181)at net.sf.saxon.expr.LetExpression.typeCheck(LetExpression.java:110)at net.sf.saxon.expr.ExpressionVisitor.typeCheck(ExpressionVisitor.java:181)at net.sf.saxon.instruct.Block.typeCheck(Block.java:447)at net.sf.saxon.expr.ExpressionVisitor.typeCheck(ExpressionVisitor.java:181)at net.sf.saxon.instruct.ParentNodeConstructor.typeCheck(ParentNodeConstructor.java:165)at net.sf.saxon.expr.ExpressionVisitor.typeCheck(ExpressionVisitor.java:181)at net.sf.saxon.instruct.Block.typeCheck(Block.java:447)at net.sf.saxon.expr.ExpressionVisitor.typeCheck(ExpressionVisitor.java:181)at net.sf.saxon.instruct.ParentNodeConstructor.typeCheck(ParentNodeConstructor.java:165)at net.sf.saxon.expr.ExpressionVisitor.typeCheck(ExpressionVisitor.java:181)at net.sf.saxon.query.XQueryExpression.<init>(XQueryExpression.java:72)at net.sf.saxon.query.QueryParser.makeXQueryExpression(QueryParser.java:121)at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:343)at net.sf.saxon.xqj.SaxonXQExpression.executeQuery(SaxonXQExpression.java:103)... 32 more
但是,本人在小计片段没有使用math:round函数的时候,脚本工作正常。后来查看java.util.Math类的API,发现Math.round()有两个函数,但是参数不同,一个为浮点型,一个为整形,所以本人怀疑上面代码报错是由于参数类型没有明确定义。因此,修改小计模块的脚本片段如下后
{xs:double(math:round((xs:float($sum2 - $sum1))*1000) div 1000.00)}
脚本工作恢复正常。
结论:
在xquery中通过命名空间引用外部函数时,如果函数有多种入参类型,那么在脚本中使用该外部函数时,要明确入参的类型。
- Xquery:There is more than one method matching the function 异常处理
- There Can Be More Than One
- appears more than once in the keychain The codesign tool requires there only be one
- mysql连接异常:The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zo
- The server timezone value 'UTC' is unrecognized or represents more than one timezone
- The server time zone value 'EDT' is unrecognized or represents more than one time zone.
- Mysql错误:The server time zone value is unrecognized or represents more than one time zone
- The server time zone value 'PDT' is unrecognized or represents more than one time zone
- The server timezone value 'xxx' is unrecognized or represents more than one time
- Python-numpy逻辑报错:The truth value of an array with more than one element is ambiguous. Us
- Python-numpy逻辑报错:The truth value of an array with more than one element is ambiguous
- mysql出现错误:The server time zone value is unrecognized or represents more than one time zone
- more than one row with the given identifier was found
- The server time zone value '?????' more than one time zone
- More than one order matters
- appears more than once in the keychain. The codesign tool requires there onl
- Read one Book more than one time
- net.sf.json.JSONException: There is a cycle in the hierarchy异常处理
- 保留数据刷入Android 4.3 出厂镜像
- C / C++ 文件文件夹操作详细整理
- 总结一下做SEO实质
- Editplus语法自定义设置
- 安卓开发-Handler学习
- Xquery:There is more than one method matching the function 异常处理
- showModalDialog想访问父窗口的数据的
- 黑马程序员---ASP.NET页面之间传递值
- 非常好的Struts2请求处理流程及源码分析(强烈推荐!)
- 怎样在Android中监听声音改变事件
- 组合键捕获事件
- but was actually of type [$Proxy19]
- showModalDialog在原窗口刷新,不弹出新的窗口
- Webservice_18_利用Handler实现方法认证