【问题标题】:Return null data for everything为所有内容返回空数据
【发布时间】:2017-02-10 23:38:52
【问题描述】:

如果我从 ParseObjectParseUser 扩展任何对象,它每次都为它包含的每个变量返回 null。例如:

public class User extends ParseUser {

    private boolean emailVerified;
    private String facebookID;

    private int fiveHundredID;
    private String fiveHundredUsername;

    private String firstName;
    private String lastName;

    private String canonicalFirstName;
    private String canonicalLastName;

    private Date birthday;
    private Photo profilePicture;

    private int followeeCount;
    private int followerCount;

}

然后我调用 User.fetchInBackground(),它不填充除 objectId、email 和其他变量之外的任何变量,这些变量仅包含在 ParseUser 类中。当然,我已经在 App 类中初始化 Parse,例如:

Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
Parse.enableLocalDatastore(getApplicationContext());
Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
        .applicationId(Const.X_PARSE_APPLICATION_ID)
        .clientKey(Const.X_PARSE_REST_API_KEY)
        .server(Const.PARSE_SERVER_URL)
        .enableLocalDataStore()
        //.addNetworkInterceptor(new JsonInterceptor())
        .build());

ParseObject.registerSubclass(User.class);

我没有使用任何 proguard,因为我在 Debug 版本上进行了测试。有什么帮助吗?此外,当我启用 LocalDataStore 时,它​​会存储我当前的用户。但是当我调用 fetchInBackground() 时,它会返回与存储本地数据相同的数据。此外,当我调用 unpinInBackground() 之后,我将调用 fetchInBackground(),它仍然会返回存储在 DB 中的本地数据。

有什么帮助吗?

非常感谢

【问题讨论】:

  • 你添加模型注释了吗?

标签: android parse-platform


【解决方案1】:

在您的模型类上方添加此注释:

@ParseClassName("User")
public class User extends ParseUser {
    ...

【讨论】:

  • @Abdenaceur_Lichiheb 好吧,我不能添加 ParseClassName,因为它会引发错误:com.parse.ParseUser cannot be cast to .Parse.User
  • @user997777 好吧,如果不添加该注释,您将无法注册对象,因为无法识别该类,您能否粘贴您的错误。
  • @Abdenaceur_Lichiheb 我已经检查过了,返回给我的是什么,它给了我来自服务器的正确数据。只是有一个问题,看起来它没有更新我本地数据存储中的数据,而是从数据存储中返回了旧数据。你知道这个问题吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多