如何从Parse Cloud Service检索特定数据

时间:2016-01-22 13:59:11

标签: java android parse-platform

我正在尝试使用以下代码从Parse获取用户的存储名称:

ParseUser puParseUser = ParseUserProfile.getCurrentUser();
String sParseUserObjectID = puParseUser.getObjectId();
ParseQuery<ParseUserProfile> pqUserProfileQuery = ParseQuery.getQuery(ParseUserProfile.class);
                    pqUserProfileQuery.getInBackground(sParseUserObjectID, new GetCallback<ParseUserProfile>() {
    @Override
    public void done(ParseObject object, ParseException e) {
          if (e == null) {
              sFirstName = object.getString(getResources().getString(R.string.keyParseFirstName));
              sMiddleName = object.getString(getResources().getString(R.string.keyParseMiddleName));
              sSurname = object.getString(getResources().getString(R.string.keyParseSurname));

              if (sFirstName == null) {
                   Log.e(KEAMapActivity.this.toString(), "ParseUser FirstName is NULL: " + sFirstName);  //  TODO: For Testing ONLY

                   txtDrawerHeader.setText(getResources().getString(R.string.sWelcome));
              } else if (sMiddleName == null) {
                   Log.e(KEAMapActivity.this.toString(), "ParseUser MiddleName is NULL: " + sMiddleName);  //  TODO: For Testing ONLY

                   txtDrawerHeader.setText(getResources().getString(R.string.sWelcome));
              } else if (sSurname == null) {
                   Log.e(KEAMapActivity.this.toString(), "ParseUser Surname is NULL: " + sSurname);  //  TODO: For Testing ONLY

                   txtDrawerHeader.setText(getResources().getString(R.string.sWelcome));
              } else {
                   Log.e(KEAMapActivity.this.toString(), "ParseUser Name is: " + sFirstName + sMiddleName + sSurname);  //  TODO: For Testing ONLY

                   sMiddleName = sMiddleName.substring(0, 1) + ".";
                   sFullName = sFirstName + " " + sMiddleName + " " + sSurname;
                   txtDrawerHeader.setText(sFullName);
              }
        } else {
              if (e.getCode() == ParseException.OBJECT_NOT_FOUND) {
                   Log.e(KEAMapActivity.this.toString(), "ParseUser OBJECT NOT FOUND");  //  TODO: For Testing ONLY

              txtDrawerHeader.setText(getResources().getString(R.string.sWelcome));

              } else {
                   Log.e(KEAMapActivity.this.toString(), "Error retrieving User's Name: " + e.getMessage());    //  TODO: For testing ONLY.
              }

              txtDrawerHeader.setText(getResources().getString(R.string.sWelcome));
       }
    }
});

上面的代码返回:OBJECT_NOT_FOUND异常。但是在我自己的良知中,我知道一个解析对象与我在此代码中提供的objectId相同,并且它是包含用户数据的用户对象。我想获得用户的第一个,中间名和姓氏。 请注意ParseUserProfilecom.parse.ParseUser类的子类。

我该怎么做才能解决这个问题?如果您需要更多详细信息或对我的代码有任何疑问,请询问。

0 个答案:

没有答案