Error evaluating field?

Hola a todos!

Estoy haciendo encuestas de opinión y tengo un problema... tengo que hacer preguntas para calificar la imagen personal de alguien.. y si es positiva (<=5) hacer una pregunta y si es negativa (>5) hacer otro tipo de pregunta

Pude desarrollarlo en xlsform y lo subi a Enketo y funciona pero cuando lo bajo a mi móvil no funciona...

el mensaje es este:
Error evaluating field 'Intencion...': java.lang.Double cannot be cast to java.lang.String

y no entiendo que significa

voy a subir mi formulario, espero me puedan ayudar tal vez este haciendo algo mal...

Ejemplo.xlsx (11.5 KB)

@Gonzalo_Martin_Godoy You are not doing anything wrong. I think this is a bug in the JavaRosa library that powers ODK Collect.

I've filed it at I'll update this topic once we have an idea of how best to fix it.

Hi, @Gonzalo_Martin_Godoy!

I've documented how range and selected() work together in the GitHub issue, and I'm copying it here too, since I believe there's actually no bug to be fixed:

At JavaRosa level, setting a string value to the range question will make the relevant expression work without errors. This makes sense because the select function in the relevant expression is intended to be used with select and select1 fields, which encode their answers as strings (xml serialized values).

Even though setting a string would make the error go away, Collect will set an decimal number answer to range fields, which wouldn't make sense to change, because those values can/will be used in other numeric expressions and having a string can/will produce problems downstream.

I think we need to focus on the combination of range and selected(), which I think it's not correctly applied. For ranges, it would make more sense to use a boolean expression like field = 5 or even field >= 5, which works independently of the types and controls of the field we want to use.

Here's a compilation of the tests I've made:

relevant Set "5" (string value) Set 5 (decimal value)
(empty) No error No error
selected( /Ejemplo/S2/Imagen_A, '5') No error - Question is shown Cast error
/Ejemplo/S2/Imagen_A = 5 No error - Question is shown No error - Question is shown
/Ejemplo/S2/Imagen_A = '5' No error - Question is shown No error - Question is shown

Por si se te hace difícil entender mi explicación en inglés, aquí va un resumen en castellano :wink:

La función selected que estás usando en el atributo relevant de Intencion_A se suele usar con campos select, no con range. Para un range tiene más sentido que uses una expresión booleana (devuelve verdadero o falso) como ${Imagen_A} = 5 o incluso ${Imagen_A} >= 5, si quieres coger los valores mayores o iguales a 5.

1 Like

So to be very explicit, in your form where you have things like this:

selected(${Imagen_A},"5") or selected(${Imagen_A},"6") or selected(${Imagen_A},"7") or selected(${Imagen_A},"8") or selected(${Imagen_A},"9") or selected(${Imagen_A},"10")

You can instead use:

${Imagen_A} >=5 and ${Imagen_A} <= 10

1 Like

Funcionó!!! Gracias!!! :+1::laughing::clap::clap::clap::clap:

1 Like

Gracias Yaw!! :clap: :clap: :clap: Funciona!!!

1 Like