Adding values to a string list

Hi, I’m trying to add a value to a string list, but operators like .add() or << are not working for me. See below where I’m trying to build a list of export measurements that includes some nuclear measurements and the Cell Mean values for every channel in the image:

def channelNum =  getCurrentServer().getMetadata().sizeC
//println ChannelNum
def Channel = getCurrentServer().getMetadata().getChannels().collect { c -> }
def columnsToInclude = new String[]{"Nucleus: Area", "Nucleus: Circularity", "Nucleus: Max caliper", "Nucleus: Min caliper", "Nucleus: Eccentricity"}
for (int i=0; i<channelNum; i++) {
   columnsToInclude.add("Cell: "+Channel[i]+" Mean"); //this line not working
print columnsToInclude

The error I get for above is:

ERROR: MissingMethodException at line 6: No signature of method: [Ljava.lang.String;.add() is applicable for argument types: (String) values: [Cell: DY405 Mean]
Possible solutions: any(), any(groovy.lang.Closure), any(groovy.lang.Closure), wait(), tail(), min()

ERROR: org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(
    java.base/java.util.concurrent.Executors$ Source)
    java.base/ Source)
    java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    java.base/java.util.concurrent.ThreadPoolExecutor$ Source)
    java.base/ Source)

I edited your post to use the ‘preformatted’ button to make it more readable.

I didn’t run the code to check, but my guess is that you should replace

def columnsToInclude = new String[]{"Nucleus: Area", "Nucleus: Circularity", "Nucleus: Max caliper", "Nucleus: Min caliper", "Nucleus: Eccentricity"}


def columnsToInclude = ["Nucleus: Area", "Nucleus: Circularity", "Nucleus: Max caliper", "Nucleus: Min caliper", "Nucleus: Eccentricity"]

This creates a list rather than an array, and lists can be added to.


Thanks. It’s not working for this application. I’m using the columnsToInclude variable in an MeasurementExporter() call here:

def outputFile = new File(outputPath)
//def entry = getProjectEntry()
entryList = []
entryList << getProjectEntry()

// Create the measurementExporter and start the export
def exporter  = new MeasurementExporter()
                  .imageList(entryList)            // Images from which measurements will be exported
                  .separator(separator)                 // Character that separates values
                  .includeOnlyColumns(columnsToInclude) // Columns are case-sensitive
                  .exportType(exportType)               // Type of objects to export
                  .exportMeasurements(outputFile)        // Start the export process

print "Export complete!"

I tried to create a comma separated list to pass in, but that does not work.

Ah ok, at the point you use it you will need an array then. This can be converted quickly in Groovy – try

.includeOnlyColumns(columnsToInclude as String[])