Firebase实时数据库无法在setValue中保存EditText字符串或String test_case =“这是测试用例消息”,但已成功保存了databaseReference.child(id_key).setValue(“ given string text”);
final Text_Strings text_strings = new Text_Strings(user_name, id_key, title_m, question_m);
// to save elements database referefernce called
databaseReference.child(id_key).setValue(text_strings, new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
if (databaseError != null) {
Log.d("Data could not be saved ", databaseError.getMessage());
} else {
// it is always saying data
Toast.makeText(getContext(), "Data saved succcessfully ", Toast.LENGTH_SHORT).show();
}
}
});
// to save id_key for test cases
databaseReference.child(id_key).setValue(test_case);
/// to save string elements for test cases
databaseReference.child(id_key).setValue("given string text");
}
});
// return view
return view;
}
}
;
答案 0 :(得分:0)
检查您是否处于测试模式或正确应用了读写规则。
您可以参考文档以在Firebase Realtime数据库中读取和写入数据:https://firebase.google.com/docs/database/android/read-and-write
请粘贴您完整的活动代码,以更好地了解您的问题。