我尝试通过Snackbar
提供的操作撤消删除操作。
以下是删除操作:
dbRef.child(footballer.getFullName()).removeValue();
当我通过下面添加的命令调用撤消操作时,获取com.google.firebase.database.DatabaseException: Failed to parse node with class
例外:
dbRef.setValue(footballer.getFullName(), footballer);
dbRef
被分配到集合的根目录:
DatabaseReference dbRef = database.getReference("footballers");
这是我的Footballer
模型:
@IgnoreExtraProperties
public class Footballer {
private String fullName;
private String desc;
private String photoUrl;
private String teamUrl;
public Footballer() {
}
public Footballer(String fullName, String desc, String photoUrl, String teamUrl) {
this.fullName = fullName;
this.desc = desc;
this.photoUrl = photoUrl;
this.teamUrl = teamUrl;
}
// getter-setter methods
}
以下是Firebase数据库的结构:
footballers
----Cristiano Ronaldo
--------fullName
--------desc
--------photoUrl
--------teamUrl
的build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.tk"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.firebase:firebase-database:11.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support:recyclerview-v7:26.1.0'
// Support Design Lib
implementation 'com.android.support:design:26.1.0'
// Swipe Action
compile 'co.dift.ui.swipetoaction:library:1.1'
// Facebook Fresco
compile 'com.facebook.fresco:fresco:0.6.1'
}
apply plugin: 'com.google.gms.google-services'