【问题标题】:groovy.lang.MissingMethodException: No signature of method: java.lang.String.call() is applicable for argument types: () values: []groovy.lang.MissingMethodException:没有方法签名:java.lang.String.call() 适用于参数类型:() 值:[]
【发布时间】:2020-07-22 13:19:19
【问题描述】:

我正在尝试使用 groovy 代码从 RESTAPI 访问数据,但出现如下错误:

groovy.lang.MissingMethodException: No signature of method: java.lang.String.call() is applicable for argument types: () values: []
Possible solutions: wait(), chars(), any(), wait(long), take(int), tap(groovy.lang.Closure)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:70)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:182)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeClosure(ScriptBytecodeAdapter.java:586)

错误主要来自代码行的以下部分:

    String requestString = getRequestStringPrefix() + sb.toString()
    readHistory(authToken,ricMap,outFile)
    writeInstFile(outFile)

我是 groovy 编码的新手,不了解问题的确切原因以及如何在代码中解决此问题。

【问题讨论】:

    标签: exception groovy method-missing


    【解决方案1】:

    使用此getRequestStringPrefix(),您正在调用具有该名称的方法或作为快捷方式调用基础对象上的方法call(),然后它看起来像getRequestStringPrefix.call()

    我不确定你的意图是什么,但是下面一行:

    String requestString = getRequestStringPrefix() + sb.toString()
    

    应该看起来像

    String requestString = getRequestStringPrefix + sb.toString()
    

    因为变量 getRequestStringPrefix(一个奇怪的 var 名称)被定义为更下方的字符串:

    String getRequestStringPrefix = """{
      "ExtractionRequest": {..."""
    

    【讨论】:

      猜你喜欢
      • 2017-06-19
      • 1970-01-01
      • 1970-01-01
      • 2021-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多