如何解决Room生成的DAO_Impl文件无法识别吸气剂
或者确实如此,但是在文件内部它尝试通过说_item.getTemperature = ...
来设置字段,而不是实际使用getter来获取值。顺便说一下,这是针对天气应用程序的。
这是我的NWSLatestMeasurements类的相关部分:
@JsonIgnoreProperties(ignoreUnkNown = true) // There are some fields in the properties JSON tree
that we can safely ignore
@Entity(tableName = "latest_measurements")
public class NWSLatestMeasurements {
@JsonProperty("timestamp")
@NonNull
@PrimaryKey
OffsetDateTime timestamp;
@JsonProperty("textDescription")
String textDescription;
double temperature;
double windSpeed;
int seaLevelPressure;
int visibility;
double relativeHumidity;
double heatIndex;
double windChill;
double precipitationLastHour;
@JsonIgnore
String cloudLayers;
@Ignore
@JsonIgnore
List<String> cloudTypes = Arrays.asList("FEW","SCT","BKN","OVC");
@Ignore
JsonNode rootNode;
// GETTERS
@JsonProperty("timestamp")
public OffsetDateTime getTimestamp(){return timestamp;
}
@JsonProperty("textDescription")
public String getTextDescription() {
return textDescription;
}
public double getTemperature() {
return temperature;
}
public double getwindSpeed() {
return windSpeed;
}
public int getSeaLevelPressure() {
return seaLevelPressure;
}
public int getVisibility() {
return visibility;
}
public double getRelativeHumidity() {
return relativeHumidity;
}
public double getHeatIndex() { return heatIndex; }
public double getwindChill() { return windChill; }
public double getPrecipitationLastHour() {return precipitationLastHour;}
public String getCloudLayers(){return cloudLayers;}
但是,生成的NWSLatestMeasurementsDAO_Impl文件尝试执行以下操作:
_item.getTemperature = _cursor.getDouble(_cursorIndexOfTemperature);
_item.getwindSpeed = _cursor.getDouble(_cursorIndexOfWindSpeed);
_item.getSeaLevelPressure = _cursor.getInt(_cursorIndexOfSeaLevelPressure);
_item.getVisibility = _cursor.getInt(_cursorIndexOfVisibility);
_item.getRelativeHumidity = _cursor.getDouble(_cursorIndexOfRelativeHumidity);
_item.getHeatIndex = _cursor.getDouble(_cursorIndexOfheatIndex);
_item.getwindChill = _cursor.getDouble(_cursorIndexOfWindChill);
_item.getPrecipitationLastHour = _cursor.getDouble(_cursorIndexOfPrecipitationLastHour);
_item.getCloudLayers = _cursor.getString(_cursorIndexOfCloudLayers);
因此,它不是在使用getter获取值(value = _item.getTemperature()
),而是尝试为我的getter函数分配值。
这很奇怪,因为它似乎在文件的前面按预期方式使用了getter。
如果我摆脱了吸气剂,并公开了所有私有字段,那就很好了,但是我宁愿不这样做。
还要说明一下,这是Room库在构建时自动生成的文件,不是我写的,如果不覆盖它,我将无法对其进行编辑。
在StackOverflow上有一个类似的答案,只有一个答案,就是说将实际的字段名称更改为“ getTemperature”等,但是我希望有人能够解决此问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。