Groovy: missing method exception when calling Java API

I've been using Groovy for a few years, but not in the last few months, so this might just be a beginner's question. I am trying to parse the log file, but when I try to do this:

myFile.eachLine { line ->

        /* 2014 Jul 30 08:55:42:645 GMT -4 BW.TMSJobService-TMSJobService-1
         * User [BW-User] - Job-2584 [Process/Common/LogAuditInfo.process/WriteToLog]:   */
        /* 1234567890123456789012345678901 */
        /* 0        1         2         3  */

        LogItem logItem = new LogItem()
        // get the time stamp
        String timestamp = line.substring(0, 31)
        SimpleDateFormat sdf = new SimpleDateFormat('yyyy MMM dd HH:mm:ss:S')
        logItem.date = sdf.parse(timestamp)
    }

      

I am getting this exception:

Exception in thread "main" groovy.lang.MissingMethodException: No method signature: java.text.SimpleDateFormat.parse () applicable for argument types: (java.lang.String, ce.readscript.TmsLogReader $ _read_closure1_closure3): [2014 30 Jul 08: 34: 47: 079 GMT -4, ce.readscript.TmsLogReader$_read_closure1_closure3@14235ed5 ] Possible solutions: parse (java.lang.String), parse (java.lang.String, java.text.ParsePosition), parse ( java.lang.String, java.text.ParsePosition), wait (), clone (), clone () at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap (ScriptBytecodeAdapter.java:55) at org.codehaus.groovy. runtime.callsite.PojoMetaClassSite.call (PojoMetaClassSite.java:46) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall (CallSiteArray.java:45)

This is always the last line in the close. If I add code after "parse" it will bomb this code. Even calling "079" .toLong () gets an error.

I see some similar errors on stack overflow, but nothing that solves my problem.

+3


source to share


2 answers


He tries to summon SimpleDateFormat::parse(String, Closure)

that doesn't exist. It seems like there is a typo somewhere. It works fine under groovy 2.1.8 and 2.3.4. You can try doing it a little more groovy to check if it has an invalid input error in your example:



new File("log.log").eachLine { line ->
  def item = new LogItem()
  def timestamp = line[0..30]
  item.date = Date.parse('yyyy MMM dd HH:mm:ss:S', timestamp)
}

      

+1


source


I used the time-tested technique of deleting a file and getting started. I haven't encountered this issue yet.



0


source







All Articles