Parse.com find()在每个查询中返回null

时间:2014-04-28 17:09:41

标签: java android listview find parse-platform

所以我尝试使用parse.com查询表并将其显示在listView中。当我执行query.find()时,它似乎无法工作。

package com.example.ketchupv4;

import java.util.List;

import com.parse.ParseObject;
import com.parse.ParseQuery;

import adapter.Group;
import adapter.SubscribeAdapter;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

public class SubscribeActivity extends Activity {
private int nNum = 0;
private String mTitle = "home";
private ListView mListView;
private SubscribeAdapter mAdapter;
private List<Group> groupsList,searchList; 
private EditText groupSearchEditText;
private Button subscribeButton;
private List<ParseObject> ob;
private TextView groupNameTextView,aboutGroupTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_subscribe_to_group);
    new AsyncTaskRunner().execute();
}
private class AsyncTaskRunner extends AsyncTask<String, String, String> {



      @Override
      protected String doInBackground(String... params) {
            try {
                ParseQuery<ParseObject> query1 =  ParseQuery.getQuery("groups");
                query1.setLimit(1000);
                query1.whereExists("groupName");
                query1.setCachePolicy(ParseQuery.CachePolicy.CACHE_THEN_NETWORK);
                ob = query1.find();

                for (ParseObject groups : ob) {
                    Group g = new    Group(groups.getString("groupName"),groups.getString("aboutGroup"));
                    groupsList.add(g);
                }

            } catch (Exception e1) {
                e1.printStackTrace();
            } finally{
            }
            return null;
      }

      /*
       * (non-Javadoc)
       * 
       * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
       */
      @Override
      protected void onPostExecute(String result) {
       // execution of result of Long time consuming operation
                      mListView = (ListView) findViewById(android.R.id.list);
          mAdapter = new     SubscribeAdapter(getBaseContext(),android.R.id.list,groupsList);
          mListView.setAdapter(mAdapter);
          mAdapter.notifyDataSetChanged();
      }
}
}

我也有这个

 package adapter;

 import com.parse.Parse;
 import com.parse.ParseACL;
 import com.parse.ParseUser;
 import android.app.Application;

 public class ParseApplication extends Application {

@Override
public void onCreate() {
    super.onCreate();

    // Add your initialization code here
    Parse.initialize(this, "k8sWxM4T6aovH2Gozkef35UDcS79yer9tT0k8PHa", "ZzYHvuuU5hh3HzOq2hjIBK9QonwXwtwuzhqFv2Bh");

    ParseUser.enableAutomaticUser();
    ParseACL defaultACL = new ParseACL();

    // If you would like all objects to be private by default, remove this line.
    defaultACL.setPublicReadAccess(true);

    ParseACL.setDefaultACL(defaultACL, true);
}

}

并在android清单中设置android:name =“adapter.ParseApplication”

以下是我的表imgur.com/IlyfKsH

的屏幕截图

我已经在androidmanifest中正确设置了所有内容。

find()总是返回null。没有意义为什么。

1 个答案:

答案 0 :(得分:0)

我可以使用以下代码获得以下结果。请尝试使用后台方法查找。

D / THE RESULT(6144):[com.parse.ParseObject@421829d0,com.parse.ParseObject @ 42183920,com.parse.ParseObject @ 421843b8,com.parse.ParseObject @ 42184e50,com.parse.ParseObject @ 42185858,com.parse.ParseObject @ 42186260,com.parse.ParseObject @ 42186c68,com.parse.ParseObject @ 42187670,com.parse.ParseObject @ 42188078,com.parse.ParseObject @ 42188a80,com.parse.ParseObject @ 42189488]

package com.t3hh4xx0r.examplecodetestingapp;

import java.security.acl.Group;
import java.util.List;

import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;

import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;

public class MainActivity extends ActionBarActivity {
    List<Group> groupsList = new List<Group>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ParseQuery<ParseObject> query1 = ParseQuery.getQuery("groups");

        query1.findInBackground(new FindCallback<ParseObject>() {
            @Override
            public void done(List<ParseObject> arg0, ParseException e) {
                if (e == null) {
                    for (ParseObject groups : arg0) {
                        Group g = new Group((String) groups.get("groupName"),
                                (String) groups.get("aboutGroup"));
                        groupsList.add(g);
                    }
                    ;
                } else {
                    e.printStackTrace();
                }
            }
        });

    }
}