microg/GmsCore · error · IllegalArgumentException
Field not found
Error message
Field not found
What it means
Thrown by DataType.indexOf(Field) when the given Field is not one of the fields defined for this DataType. Each DataType has a fixed field list; indexOf resolves a Field to its positional index (used to read values from a DataPoint) and rejects unknown fields.
Source
Thrown at play-services-fitness/src/main/java/com/google/android/gms/fitness/data/DataType.java:170
return fields;
}
/**
* Returns the namespaced name which uniquely identifies this data type.
*/
@NonNull
public String getName() {
return name;
}
/**
* Returns the index of a field.
*
* @throws IllegalArgumentException If field isn't defined for this data type.
*/
public int indexOf(@NonNull com.google.android.gms.fitness.data.Field field) {
int indexOf = this.fields.indexOf(field);
if (indexOf < 0) throw new IllegalArgumentException("Field not found");
return indexOf;
}
/**
* Returns a list of output aggregate data types for the specified {@code inputDataType}.
* <p>
* To check if a data type is supported for aggregation, check that the returned list is not empty
* {@code DataType.getAggregatesForInput(dataType).isEmpty()}.
*
* @deprecated Use {@link #getAggregateType()} instead.
*/
@NonNull
@Deprecated
public static List<DataType> getAggregatesForInput(@NonNull DataType inputDataType) {
DataType aggregateType = inputDataType.getAggregateType();
if (aggregateType == null) return Collections.emptyList();
return Collections.singletonList(aggregateType);
}View on GitHub (pinned to 157c9d86ac)
Solutions
- Use the correct Field constant for that DataType (check the DataType's getFields() list).
- Guard with dataType.getFields().contains(field) before calling indexOf.
- Read values via dataPoint.getValue(field) instead of manual index math where possible.
- Loop over dataType.getFields() rather than assuming field order/names.
Example fix
// before
int i = DataType.TYPE_STEP_COUNT_DELTA.indexOf(Field.FIELD_CALORIES); // throws
// after
Field f = Field.FIELD_CALORIES;
if (DataType.TYPE_STEP_COUNT_DELTA.getFields().contains(f)) {
int i = DataType.TYPE_STEP_COUNT_DELTA.indexOf(f);
} Defensive patterns
Strategy: validation
Validate before calling
if (!dataType.getFields().contains(field)) throw new IllegalArgumentException(field.getName() + " not valid for " + dataType.getName());
Type guard
Optional<Integer> safeIndexOf(DataType dt, Field f) { int i = dt.getFields().indexOf(f); return i >= 0 ? Optional.of(i) : Optional.empty(); } Try / catch
try { int i = dataType.indexOf(field); } catch (IllegalArgumentException e) { log.warn("Field {} not in {}", field.getName(), dataType.getName()); } Prevention
- Look up the Field constant from the DataType's docs/getFields(), not memory.
- Iterate dataType.getFields() rather than assuming field membership.
- Avoid manual index math; use dataPoint.getValue(field).
- Pin play-services-fitness versions and check Field availability per version.
When it happens
Trigger: Calling dataType.indexOf(field) with a Field object that does not belong to that DataType — e.g. Field.FIELD_CALORIES on DataType.TYPE_STEP_COUNT_DELTA, or a Field created from a different data type's definition.
Common situations: Hardcoding the wrong Field constant for a data type; iterating fields from one DataType while indexing into another; version drift where a Field exists in a newer play-services-fitness release but the data type in question never had it.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- streamName must be set
- deleteAll was set to true but keys were also provided
- Element in keys cannot be null or empty
- deleteAll=true but keys are provided
- retrieveAll was set to true but other constraint(s) was also
AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06).
Data as JSON: /api/errors/542147f283fdc52e.
Report an issue: GitHub.