简体   繁体   中英

Parse.com can't retrieve objects

I'm trying to retrieve objects using parse, however I get the error

gameScore cannot be resolved.

I'm following the exact explanation on https://parse.com/docs/android_guide#objects-classes

What am I doing wrong ?

public class ParseStarterProjectActivity extends Activity {
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ParseAnalytics.trackAppOpenedInBackground(getIntent());

    ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
    query.getInBackground("gDlXAym3S7", new GetCallback<ParseObject>() {
        public void done(ParseObject object, ParseException e) {
            if (e == null) {
                System.out.println("object found");
                int score = gameScore.getInt("score");
                String playerName = gameScore.getString("playerName");
                boolean cheatMode = gameScore.getBoolean("cheatMode");
            } else {
                System.out.println("object not found");
            }
        }
    });
  }
}   

I'm looking to your code and you don't declare any class called "gameScore". I think what you want is the next code:

public class ParseStarterProjectActivity extends Activity {
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ParseAnalytics.trackAppOpenedInBackground(getIntent());

    ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
    query.getInBackground("gDlXAym3S7", new GetCallback<ParseObject>() {
        public void done(ParseObject object, ParseException e) {
            if (e == null) {
                System.out.println("object found");
                int score = object.getInt("score");
                String playerName = object.getString("playerName");
                boolean cheatMode = object.getBoolean("cheatMode");
            } else {
                System.out.println("object not found");
            }
        }
    });
  }
}  

So pay attention to the ParseObject you get after the query is done: it's declared as "object", and you will need it to get all information stored inside of it.

Hope it helps, Regards!!

除了Fer答案之外,您还应该检查query.getInBackground("gDlXAym3S"...对象ID是否正确,并检查该对象在Parse仪表板(列:ACL)中是否具有“公共读取”访问权限。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM