Lost using Lists

I wish to use a list to select the description of a sensor function. I guess I could use a Map but now that I've started using the List form I'm determined to figure out how to use it.

Can anyone see where I've gone astray?

App Code section defining lists

// =====================================================
//Needed for lists to be available in methods
@Field static List<String> DescList = ['Outside Temp = ', 'Outside Humidity = ', 'Outside Dew Point = ','Pressure = ','Inside Temp = ', 'Inside Humidity = ', 'Alarm Status: ']
@Field static List<String> UnitsList = [ ' °F', ' %RH',' °F','hPa',' °F',' %RH']

// ______________________________________________________
def installed() {
    initialize()
}

Section of code where I'm trying to select a member of the list

    int index = 1
    log.info "DescList 1 = $DescList[index]"  // same result with $DescList(index)

Log Error

DescList 1 = Outside Temp = , Outside Humidity = , Outside Dew Point = , Pressure = , Inside Temp = , Inside Humidity = , Alarm Status:

I have seen very wonky things happen when you don't put curly brackets {} around variables within your string. I took your exact code and added them around your variable and it fixed it. FWIW I always use {} just to be sure.

log.info "DescList 1 = $DescList[index]" // same result with $DescList(index)
log.info "DescList 1 = ${DescList[index]}" // same result with $DescList(index)

2 Likes