2016-08-29 7 views
0

私のアプリはユーザの場所データをFirebase Realtime Databaseに保存します。私がやろうとしているのは、そのデータの一部を取り出して、アプリ内で処理することです。 Firebase DBから目的のデータを取得することができました(デバッグによってチェックされています)。今私はローカル変数にデータを格納したいと思います。私は1つの値を除いてすべての値を保存することができます(デバッガは、それがヌルであることを示しますが、それはdatasnapshotにあります)。 FirebaseからのデータはUserDataLocationオブジェクト形式であり、次は同じのためのクラスです:Firebase DBからデータを取得し、ローカル変数に格納する:Android

UserDataLocationクラス:

public class UserLocationData { 

    String mobile, name, latitude, longitude, proximity, connection_limit, last_updated; 

    public UserLocationData() { 
    } 

    public UserLocationData(String mobile, String name, String latitude, String longitude, String proximity, String connection_limit, String last_updated) { 

     this.mobile = mobile; 
     this.name = name; 
     this.latitude = latitude; 
     this.longitude = longitude; 
     this.proximity = proximity; 
     this.connection_limit = connection_limit; 
     this.last_updated = last_updated; 
    } 

    public String getMobile() { 
     return mobile; 
    } 

    public void setMobile(String mobile) { 
     this.mobile = mobile; 
    } 

    public String getName() { 
     return name; 
    } 

    public void setName(String name) { 
     this.name = name; 
    } 

    public String getLatitude() { 
     return latitude; 
    } 

    public void setLatitude(String latitude) { 
     this.latitude = latitude; 
    } 

    public String getLongitude() { 
     return longitude; 
    } 

    public void setLongitude(String longitude) { 
     this.longitude = longitude; 
    } 

    public String getProximity() { 
     return proximity; 
    } 

    public void setProximity(String proximity) { 
     this.proximity = proximity; 
    } 

    public String getConnection_limit() { 
     return connection_limit; 
    } 

    public void setConnection_limit(String connection_limit) { 
     this.connection_limit = connection_limit; 
    } 

    public String getLast_updated() { 
     return last_updated; 
    } 

    public void setLast_updated(String last_updated) { 
     this.last_updated = last_updated; 
    } 
} 

ここでは、私がデータを取得し、保存しています方法です:

    @Override 
        public void onDataChange(DataSnapshot dataSnapshot) { 

         for (DataSnapshot child : dataSnapshot.getChildren()) { 

          userLocationData = child.getValue(UserLocationData.class); 
          String connectionKey = child.getKey(); 

          if (!connectionKey.equals(currentUserMobile)) { 

           for (int count = 0; count <= Integer.parseInt(connections_limit); count++) { 

            **String last_updated = userLocationData.last_updated;** //this is showing null in debugger 

            Location connectionLocation = getLocationFromLatLng(userLocationData.latitude, userLocationData.longitude); 

            {......} 
           } 
          } 
         } 
        } 
       } 

String last_updated = userLocationData.last_updated;を除くすべての変数に値があります。

誰でもこの問題を解決するのに役立ちますか?

答えて

3

私は私の問題を解決しました。このエラーは軽微ではありましたが重要でした。実際には、私はlast updatedをキーとして使用して、最後に更新された時刻を保存していました。問題は、この鍵のフォーマットにありました。それはlast_updatedまたは何か他のものだったはずですが、firebaseデータベースはspacesのキーを無効とみなすようです。だから、鍵をlast_updatedに変更して問題を解決しました。

誰かを助けることを願っています。

関連する問題