我正在尝试在Firebase实时数据库上保存一些数据,并且不断收到重复的字段
我试图更改模型,但没有任何改变
submitVideoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String locationName;
locationName = mLocationSpinnerName;
if(!locationInput.getText().toString().equals("")){
locationName = locationInput.getText().toString();
}
LocationData tompkins = new LocationData(locationName, 30,
31);
String userid = mFirebaseUser.getEmail().substring(0,
mFirebaseUser.getEmail().indexOf("@"));
String cleanUserId = userid.replaceAll("\\W", "");
updateUserInfo(cleanUserId, mFirebaseUser.getEmail(),
"nsaofdhiqo3", tompkins);
}
});
}
private void updateUserInfo(String userId, String email, String videoId,
LocationData location) {
VideoEntry videoEntry = new VideoEntry(videoId, location);
UserData user = new UserData(email, videoEntry);
mDatabaseRef.child("users").child(userId).setValue(user);
}
VideoEntry.Java
public class VideoEntry {
public String text;
public String mVideoId;
public LocationData mLocationData;
public VideoEntry() {}
public VideoEntry(String text, String videoId) {
this.text = text;
mVideoId = videoId;
}
public VideoEntry(String videoId, LocationData locationData) {
mVideoId = videoId;
mLocationData = locationData;
}
public String getText() {
return text;
}
public String getVideoId() {
return mVideoId;
}
}
UserData.Java
public class UserData {
public String mName;
public String mVideoId; //TO BE REMOVED
public LocationData mLocationData;
public ArrayList<VideoEntry> mVideoEntries;
public VideoEntry mVideoEntry; //TO BE REMOVED
public UserData(){}
public UserData(String name){
mName = name;
}
public UserData(String name, String videoId, LocationData locationData){
mName = name;
mVideoId = videoId;
mLocationData = locationData;
}
public UserData(String name, String videoId, LocationData locationData, ArrayList<VideoEntry> videoEntries){
mName = name;
mVideoId = videoId;
mLocationData = locationData;
mVideoEntries = videoEntries;
}
public UserData(String name, VideoEntry videoEntry){
mName = name;
mVideoEntry = videoEntry;
}
public UserData(String name, VideoEntry videoEntry, LocationData locationData){
mName = name;
mVideoEntry = videoEntry;
mLocationData = locationData;
}
}
LocationData.java
public class LocationData {
public String mName;
public double mLongitude;
public double mLatitude;
public LocationData(){}
public LocationData(String name, double longitude, double latitude) {
mName = name;
mLongitude = longitude;
mLatitude = latitude;
}
}
我只是想拥有一个一个字段,而不是两个videoID(mVideoId和videoID),我想这可能是Java“陷阱”吗?
答案 0 :(得分:0)
Firebase默认情况下会序列化/反序列化 public 字段和“属性”(由JavaBean标准getter和setter标识)。
将您的成员字段标记为私有字段应确保它们不会被写入数据库:
private String mVideoId;
或者,您也可以将公共领域或获取者/设置者标记为@Exclude
:
@Exclude public String mVideoId;