无法从android中获取解析表中的数据

时间:2015-07-01 10:51:25

标签: android parse-platform

我正在使用解析这里是我的应用程序的图像![解析应用程序图片] [1]

现在我尝试了很多来获取GPSLocation表的纬度和经度,但我无法获取数据。我添加了权限,如解析文档中所述,但我仍然无法获取数据是我的代码。

ParseQuery<ParseObject> query = ParseQuery.getQuery("GPsLocation");

                query.getInBackground("wYo1DfMw0g", new GetCallback<ParseObject>() {
                    public void done(ParseObject object, ParseException e) {
                        if (e == null) {
                            Toast.makeText(getApplicationContext(), "nothing found", Toast.LENGTH_SHORT).show();
                            // object will be your game score
                        } else {
                            // something went wrong
                        }
                    }
                });

我也试过这个示例代码

 request.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


				ParseQuery query = new ParseQuery("GPsLocation");
				query.getInBackground("p3VKhrJPKt", new GetCallback() {
					public void done(ParseObject object, ParseException e) {
						if (e == null) {
							String latitude = object.getString("latitude");
							Toast.makeText(getApplicationContext(),"nothing found"+latitude,Toast.LENGTH_SHORT).show();
							// object will be your game score
						} else {
							// something went wrong
						}
					}
				});

现在请帮助我[1]:http://i.stack.imgur.com/SQTu2.png

1 个答案:

答案 0 :(得分:0)

尝试这种方式可以帮助您。

首先使用初始化方法

Parse.initialize(context,getString(R.string.parseId),                 的getString(R.string.parseSecret));

Parse.initialize(context, getString(R.string.parseId),
            getString(R.string.parseSecret));
    ParseUser.enableAutomaticUser();
    ParseACL defaultACL = new ParseACL();
    defaultACL.setPublicReadAccess(true);
    defaultACL.setPublicWriteAccess(true);
    ParseACL.setDefaultACL(defaultACL, true);

然后,

private void getDataFromGpsLocation (){
    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("GPsLocation");

    try {
        try {
            ob = query.find();
        } catch (com.parse.ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } catch (ParseException e) {
        Log.e("Error", e.getMessage());
        e.printStackTrace();
    }
    try {
        for (ParseObject parseobj : ob) {
        // u get your field name 
            Log.e("score" ,""+parseobj.latitude);
        }
    } catch (Exception e) {

    }
}