gpt4 book ai didi

android - 从 Firebase DB 中检索失败的值,得到 null 而不是预期的 String

转载 作者:行者123 更新时间:2023-11-29 19:16:17 26 4
gpt4 key购买 nike

我在我的 Android 应用程序和 FirebaseUI 中使用 Firebase 数据库图书馆。

enter image description here

我设计了数据模型(现在故意排除了一些键):

/**
Retrieving CarPark object from Firebase db
*/

public class CarParkData {

private String mTitle;
private String mSponsor;
private String mAddress;
private String mDesc;

// default parameters constructor required for Firebase for data retrieval
public CarParkData() {

}

// constructor
public CarParkData(String title, String sponsor, String description, String address1) {
mTitle = title;
mSponsor = sponsor;
mAddress = address1;
mDesc = description;
}

public String getTitle() {
return mTitle;
}

public void setTitle(String title) {
mTitle = title;
}

public String getSponsor() {
return mSponsor;
}

public void setSponsor(String sponsor) {
mSponsor = sponsor;
}

public String getAddress() {
return mAddress;
}

public void setAddress(String address1) {
mAddress = address1;
}

public String getDesc() {
return mDesc;
}

public void setDesc(String description) {
mDesc = description;
}
}

FirebaseListAdapter 使用:

mAdapter = new FirebaseListAdapter<CarParkData>(getActivity(), CarParkData.class,
R.layout.test, ref) {

@Override
protected void populateView(View v, CarParkData model, int position) {
((TextView)v.findViewById(R.id.text_one)).setText(model.getTitle());
((TextView)v.findViewById(R.id.text_two)).setText(model.getAddress());
((TextView)v.findViewById(R.id.text_three)).setText(model.getSponsor());

String test = model.getTitle(); // test: "Q-Park Victoria Square
String test2 = model.getSponsor(); // test2: "false"
String test3 = model.getAddress(); // test3: "null"
String test4 = model.getDesc(); // test4: "null"

使用的 JSON 对象:

{
"-KhguCEtT6TpPPmuvMvY": {
"title": "Q-Park Victoria Square",
"owner": "Q-Park",
"address1": "Victoria Street 1",
"address_line2": {
"post_code": "BT1 4QG",
"city": "Kekity"
},
"description": "Located in the heart of Kekistan, Q-Park Victoria Square has direct access to each floor of Victoria Square Mall",
"image_url": "image_url",
"parking_capacity": 1000,
"available_spaces": 70,
"max_vehicle_height": 2.1,
"schedule": {
"monday": {
"24_7": true,
"open": "null",
"close": "null"
},
"tuesday": {
"24_7": true,
"open": "null",
"close": "null"
},
"wednesday": {
"24_7": true,
"open": "null",
"close": "null"
},
"thursday": {
"24_7": true,
"open": "null",
"close": "null"
},
"friday": {
"24_7": true,
"open": "null",
"close": "null"
},
"saturday": {
"24_7": true,
"open": "null",
"close": "null"
},
"sunday": {
"24_7": true,
"open": "null",
"close": "null"
}
},
"pricing": {
"24_7": true,
"schedule": {
"day": {
"hourly_rate": 3.00,
"start_time": "8:00",
"end_time": "19:00"
},
"night": {
"hourly_rate": 4.50,
"start_time": "8:00",
"end_time": "19:00"
}
},
"24_7_pass": 18.00,
"day_pass": "null",
"night_pass": "null"
},
"free_until": 0,
"disabled_access": true,
"city_picker": "kekity",
"sponsor": "false",
"location": "null"
}

getTitlegetSponsor 返回期望值,而 getAddressgetDesc 在需要 String 时返回 null。任何人都可以确定发生了什么事吗?

最佳答案

模型中的 getter/setter 名称必须与数据库中的属性名称完全匹配。在您的数据库中,您使用 address1description。这些属性的 getter/setter 必须是:

public String getAddress1() {
return mAddress;
}

public void setAddress1(String address1) {
mAddress = address1;
}

public String getDescription() {
return mDesc;
}

public void setDescription(String description) {
mDesc = description;
}

关于android - 从 Firebase DB 中检索失败的值,得到 null 而不是预期的 String,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43426362/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com