私はFirebaseを使用しています。私はデータを取得するためにいくつかのクエリを実行していますし、addChildEventListener
を使用しています。私もaddValueEventListener
を試してみました。 dataSnapshot.getValue()
の応答はHashMap
です。クラスFirebaseクエリハッシュマップ
最初のケースのHashMap
の各キーは、私のクラスのフィールドを表しています。
HashMap
をクラス\ modelに変換する方法はありますか?それとも、私が持っているクラスごとにカスタムをしなければならないのですか?
dataSnapshot.getValue(Trip.class);
を使用できることがわかりましたが、DataseException
がスローされます。
私のリフレクションの経験はほとんどありませんが、理論的には私はそれを使うことができますが、どうすればよいか分かります。
ありがとうございました。 (デバッグ中)(それを表示するにはもちろん、それのすべてではない)
EDIT 旅行モデルは、例えば
public class Trip implements Model
{
private String ID;
private String driverID;
private LatLng addressFrom;
private LatLng addressTo;
private List<LatLng> locationList;
private boolean isActive;
}
HashMap
応答は次のよう
result = {[email protected]} size = 14
0 = {[email protected]} "fullAddress" -> "this is the address"
1 = {[email protected]} "addressFrom" -> " size = 2"
2 = {[email protected]32} "state" -> "0"
3 = {[email protected]} "distanceMeter" -> "706"
4 = {[email protected]} "id" -> "-KX5Ihn7E_g8HEmsXXL3"
5 = {[email protected]} "duration" -> "157"
6 = {[email protected]} "timeMilliSeconds" -> "1479722067649"
7 = {[email protected]} "driverID" -> "RZZplHcojGWRoJdRH2SOswQvSBO2"
8 = {[email protected]} "addressTo" -> " size = 2"
9 = {[email protected]} "locationList" -> " size = 3"
10 = {[email protected]} "length" -> "706"
11 = {[email protected]} "active" -> "false"
12 = {[email protected]} "passengerCount" -> "1"
13 = {[email protected]} "endAddressText" -> "this is the end address text"
EDIT 2であります(getValue(Trip.lassからの例外)
com.google.firebase.database.DatabaseException:クラスcom.google.android.gms.maps.model.LatLngは、引数なしのコンストラクタが欠落している
クラスモデルと応答ハッシュマップを投稿できますか? – rhari
@rhari編集を確認してください –
dataSnapshot.getValue(Trip.class)を使用しているときにlogcatの例外を通知することもできます。 ? – rhari