laxmi
laxmi

Reputation: 865

how to read parameters from console to method in groovy?

I am new to groovy.I am reading values for 2 variables from console with below lines of code.

System.in.withReader {   
  println "Version: "  
  version = it.readLine()  
  println "Doc Type:"  
  Doc=it.readLine()  
  call getBillID(version,Doc)
}

getBillid method is as below,

def getBillID(int version,int doc)
{  
  allNodes.BillID.each {
    theregularExpression=/\d+_\d+_\d+_\d_\d+_\d+_\d_${version}_${Doc}_\d+_\d+/
    if(it != "" && it =~ theregularExpression) {
      println "******" + it
    }
  }
}

now i want to use those variable values in my getBILLID method but i am getting error as

No signature of method: ReadXML.getBillID() is applicable for argument types: (java.lang.String, java.lang.String) values: [9, ]

where i went wrong.can any one tell me plz..

Upvotes: 1

Views: 993

Answers (2)

tim_yates
tim_yates

Reputation: 171054

In addition to @Kalarani's answer, you could also do this:

System.in.withReader {
  print "Version: "
  int version = it.readLine() as int
  print "Doc Type: "
  int doc = it.readLine() as int
  getBillID( version, doc )
}

As an aside; I would be careful with your capitalisation and variable names, ie: you have a variable called Doc with a capital letter. This is not the standard naming scheme, and you are best using all lowercase for variable names. You can see where it has got confused in the getBillID method. The parameter is called doc (all lowercase), but in the regular expression you reference ${Doc} (uppercase again).

This sort of thing is going to end up causing you a world of pain and bugs that might take you longer to find

Upvotes: 3

Kalarani
Kalarani

Reputation: 407

Where is the getBillId() method defined? and what is the signature of the method? It would help understanding your problem if you could post that.

Upvotes: 0

Related Questions