{"record":{"id":"3457e26a47e3c01c","repo":"microg/GmsCore","slug":"the-number-of-values-does-not-match-the-number-of","errorCode":null,"errorMessage":"The number of values does not match the number of fields","messagePattern":"The number of values does not match the number of fields","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-fitness/src/main/java/com/google/android/gms/fitness/data/DataPoint.java","lineNumber":160,"sourceCode":"\n    DataSource getOriginalDataSourceIfSet() {\n        return originalDataSource;\n    }\n\n    long getRawTimestamp() {\n        return rawTimestamp;\n    }\n\n    /**\n     * Sets the values of this data point, where the format for all of its values is float.\n     *\n     * @param values The value for each field of the data point, in order.\n     * @deprecated Use {@link DataPoint.Builder} to create {@link DataPoint} instances.\n     */\n    @Deprecated\n    public DataPoint setFloatValues(float... values) {\n        if (values.length != this.getDataType().getFields().size())\n            throw new IllegalArgumentException(\"The number of values does not match the number of fields\");\n        for (int i = 0; i < values.length; i++) {\n            this.values[i].setFloat(values[i]);\n        }\n        return this;\n    }\n\n    /**\n     * Sets the values of this data point, where the format for all of its values is int.\n     *\n     * @param values The value for each field of the data point, in order.\n     * @deprecated Use {@link DataPoint.Builder} to create {@link DataPoint} instances.\n     */\n    @Deprecated\n    public DataPoint setIntValues(int... values) {\n        if (values.length != this.getDataType().getFields().size())\n            throw new IllegalArgumentException(\"The number of values does not match the number of fields\");\n        for (int i = 0; i < values.length; i++) {\n            this.values[i].setInt(values[i]);","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-fitness/src/main/java/com/google/android/gms/fitness/data/DataPoint.java#L142-L178","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Match the float array length to dataSource.getDataType().getFields().size() before calling.","Migrate to the recommended DataPoint.Builder API, which sets values per-field explicitly and avoids positional mismatches.","If values are computed dynamically, assert/validate values.length against the field count and truncate or pad deliberately."],"exampleFix":"// before\ndataPoint.setFloatValues(speed); // TYPE_SPEED has 1 field; ok. But for multi-field types:\ndataPoint.setFloatValues(lat, lng, accuracy); // wrong count\n// after\nList<Field> fields = dataPoint.getDataType().getFields();\nfloat[] vals = { lat, lng, accuracy };\nif (vals.length == fields.size()) {\n    dataPoint.setFloatValues(vals);\n}","handlingStrategy":"validation","validationCode":"int fieldCount = dataPoint.getDataType().getFields().size();\nif (values.length != fieldCount) throw new IllegalArgumentException(\"expected \" + fieldCount + \" values, got \" + values.length);","typeGuard":null,"tryCatchPattern":"try { dataPoint.setFloatValues(values); } catch (IllegalArgumentException e) { Log.e(TAG, \"value/field count mismatch for \" + dataPoint.getDataType().getName()); }","preventionTips":["Look up the DataType's field count before building the values array.","Prefer DataPoint.Builder with per-field setValue calls over the deprecated varargs API.","Don't assume all fitness DataTypes are single-field; check per type.","When migrating code between DataTypes, re-map values explicitly by field name."],"tags":["google-fit","fitness","argument-count","android"],"backgroundTag":"invalid-argument-value","analyzedSha":"157c9d86ac46c195a86c2f15ab55c84036223f95","analyzedAt":"2026-09-06T17:27:33.892Z","contentChangedAt":"2026-09-06T17:27:33.892Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}