我见过其他人问过这个问题,但在我看来,我已经完成了所有必需的事情,但我仍然没有让它发挥作用。我在课堂上找到了车辆类型的No setter / field 没有在课堂上找到抵达时间的字母/字段 没有在课程上找到的驱动程序编号的字母/字段 没有在课堂上找到的车辆编号的字母/字段 在课堂上找不到出发时间的设定者/字段 没有在课程
上找到的部分金额付款的设定者/字段public class TruckDetailsActivity {
//name and address string
@JsonProperty("Transporter")
private String Transporter;
@JsonProperty("Driver Name")
private String DriverName;
public void setVehicleType(String vehicleType) {
VehicleType = vehicleType;
}
@JsonProperty("Driver Number")
private String DriverNumber;
@JsonProperty("Vehicle Number")
private String VehicleNumber;
@JsonProperty("Date")
private String Date;
@JsonProperty("aps")
private String aps;
@JsonProperty("email")
private String email;
private String key;
@JsonProperty("Time of Arrival")
private String TimeofArrival;
@JsonProperty("Cost")
private String Cost;
@JsonProperty("Time of Departure")
private String TimeofDeparture;
@JsonProperty("Partial Amount Paid")
private String PartialAmountPaid;
@JsonProperty("Vehicle Type")
private String VehicleType;
@JsonProperty("Cash Handover")
private String CashHandover;
@JsonProperty("Operator")
private String Operator;
public TruckDetailsActivity() {
/*Blank default constructor essential for Firebase*/
}
public TruckDetailsActivity(String a){
}
public TruckDetailsActivity(String k, String s, String index, String index1, String index2, String index3) {
this.key=k;
email=s;
Transporter =index;
DriverNumber =index1;
Date =index2;
aps =index3;
}
@JsonProperty("Key")
public String getKey(){
return this.key;
}
public void setKey(String key){
this.key=key;
}
//Getters and setters
public String getTransporter() {
return this.Transporter;
}
public void setTransporter(String contractorname) {
this.Transporter = contractorname;
}
public String getDriverName() {
return this.DriverName;
}
public void setDriverName(String driverName) {
this.DriverName = driverName;
}
public String getDriverNumber() {
return this.DriverNumber;
}
public String getVehicleNumber() {
return this.VehicleNumber;
}
public String getDate() {
return this.Date;
}
public void setDate(String date) {
this.Date = date;
}
public String getAps() {
return this.aps;
}
public void setAps(String aps) {
this.aps = aps;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email){this.email=email;}
public String getTimeofArrival() {
return this.TimeofArrival;
}
public String getCost() {
return this.Cost;
}
public void setCost(String T) {
this.Cost = T;
}
public String getTimeofDeparture() {
return TimeofDeparture;
}
public String getPartialAmountPaid() {
return PartialAmountPaid;
}
public String getVehicleType() {
return VehicleType;
}
public String getCashHandover() {
return CashHandover;
}
public void setCashHandover(String cashHandover) {
CashHandover = cashHandover;
}
public String getOperator() {
return Operator;
}
public void setOperator(String operator){this.Operator=operator;}
This is my Java file from where i call the above class.
Query queryRef = reference.child("users").child("data").orderByChild(sort);
queryRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds:dataSnapshot.getChildren()){
TruckDetailsActivity post = ds.getValue(TruckDetailsActivity.class);
post.setKey(ds.getKey());
Log.d("post", post.getKey());
TruckDetailsActivity obj = new TruckDetailsActivity(post.getKey(), post.getEmail(), post.getTransporter(), post.getDriverNumber(), post.getDate(), post.getAps());
list.add(index, obj);
Log.d("list", String.valueOf(list.get(index)));
index++;
}
mAdapter = new MyRecyclerViewAdapter(list);
mAdapter.notifyDataSetChanged();
Log.d("count of list", String.valueOf(mAdapter.getItemCount()));
mRecyclerView.setAdapter(mAdapter);
pb.setVisibility(View.GONE);
linearLayout.setVisibility(View.VISIBLE);
}
@Override
public void onCancelled(DatabaseError firebaseError) {
}
});
Gradle Build
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.potenza_pvt_ltd.AAPS"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.1'
compile 'com.android.support:cardview-v7:22.0.0'
compile 'com.android.support:recyclerview-v7:22.0.0'
//compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.github.brnunes:swipeablerecyclerview:1.0.2'
compile 'com.google.firebase:firebase-database:9.0.0'
compile 'com.google.firebase:firebase-auth:9.0.0'
compile 'com.google.firebase:firebase-storage:9.0.0'
compile files('libs/poi-3.14-20160307.jar')
compile files('libs/joda-time-2.9.4.jar')
compile files('libs/jackson-annotations-2.2.3.jar')
}
apply plugin: 'com.google.gms.google-services'
答案 0 :(得分:2)
您好像使用以前版本的应用程序(使用旧版本(2.x.x)SDK)创建了Firebase数据库。旧版SDK使用Jackson进行JSON转换。您使用了Jackson注释@JsonProperty
并指定了包含空格的名称。
您现在已经升级了您的应用程序以使用新的SDK,该SDK不使用Jackson而是需要JavaBean getter / setter命名约定来将POJO类转换为JSON或从JSON转换。这会对名称中包含空格的数据库字段产生问题,例如“驱动程序编号”。
我所知道的唯一解决方案是转到Firebase控制台并将数据库导出到JSON文件,手动编辑它以替换包含空格的字段名称,然后导回到Firebase。导出/导入操作位于Firebase控制台数据库选项卡右上角的溢出菜单图标(三个垂直点)中。