microg/GmsCore · error · IllegalArgumentException

The number of values does not match the number of fields

Error message

The number of values does not match the number of fields

What it means

DataPoint.setFloatValues(float...) assigns one value per field of the DataPoint's DataType. It throws IllegalArgumentException when the varargs array length differs from the DataType's field count, because each Field must receive exactly one value. This deprecated API remains for backwards compatibility.

Source

Thrown at play-services-fitness/src/main/java/com/google/android/gms/fitness/data/DataPoint.java:160

    DataSource getOriginalDataSourceIfSet() {
        return originalDataSource;
    }

    long getRawTimestamp() {
        return rawTimestamp;
    }

    /**
     * Sets the values of this data point, where the format for all of its values is float.
     *
     * @param values The value for each field of the data point, in order.
     * @deprecated Use {@link DataPoint.Builder} to create {@link DataPoint} instances.
     */
    @Deprecated
    public DataPoint setFloatValues(float... values) {
        if (values.length != this.getDataType().getFields().size())
            throw new IllegalArgumentException("The number of values does not match the number of fields");
        for (int i = 0; i < values.length; i++) {
            this.values[i].setFloat(values[i]);
        }
        return this;
    }

    /**
     * Sets the values of this data point, where the format for all of its values is int.
     *
     * @param values The value for each field of the data point, in order.
     * @deprecated Use {@link DataPoint.Builder} to create {@link DataPoint} instances.
     */
    @Deprecated
    public DataPoint setIntValues(int... values) {
        if (values.length != this.getDataType().getFields().size())
            throw new IllegalArgumentException("The number of values does not match the number of fields");
        for (int i = 0; i < values.length; i++) {
            this.values[i].setInt(values[i]);

View on GitHub (pinned to 157c9d86ac)

Solutions

  1. Match the float array length to dataSource.getDataType().getFields().size() before calling.
  2. Migrate to the recommended DataPoint.Builder API, which sets values per-field explicitly and avoids positional mismatches.
  3. If values are computed dynamically, assert/validate values.length against the field count and truncate or pad deliberately.

Example fix

// before
dataPoint.setFloatValues(speed); // TYPE_SPEED has 1 field; ok. But for multi-field types:
dataPoint.setFloatValues(lat, lng, accuracy); // wrong count
// after
List<Field> fields = dataPoint.getDataType().getFields();
float[] vals = { lat, lng, accuracy };
if (vals.length == fields.size()) {
    dataPoint.setFloatValues(vals);
}
Defensive patterns

Strategy: validation

Validate before calling

int fieldCount = dataPoint.getDataType().getFields().size();
if (values.length != fieldCount) throw new IllegalArgumentException("expected " + fieldCount + " values, got " + values.length);

Try / catch

try { dataPoint.setFloatValues(values); } catch (IllegalArgumentException e) { Log.e(TAG, "value/field count mismatch for " + dataPoint.getDataType().getName()); }

Prevention

When it happens

Trigger: Calling setFloatValues with an array whose length != dataSource.getDataType().getFields().size() — e.g. passing one float to TYPE_STEP_COUNT_DELTA (1 field is fine) but two floats, or passing 3 floats to a 10-field TYPE_LOCATION_SAMPLE; also passing a zero-length array.

Common situations: Assuming every fitness DataType has one field; copying code between DataTypes with different field counts; building values dynamically from a list whose size drifted from the field list; using raw DataPoint construction instead of the newer DataPoint.Builder.

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


AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06). Data as JSON: /api/errors/3457e26a47e3c01c. Report an issue: GitHub.