本文介绍了Parse.com find()方法返回null每次查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我尝试使用parse.com查询表,并在ListView显示。当我做了query.find()它似乎没有工作。

So I am trying to Query a table using parse.com and display it in a listView. When I do the query.find() it doesnt seem to work.

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清单我设置机器人:名字=adapter.ParseApplication

and in the android manifest i set android:name="adapter.ParseApplication"

下面是我的表imgur.com/IlyfKsH的屏幕截图

Here is a screen shot of my table imgur.com/IlyfKsH

我有我的一切androidmanifest设置正确。

I have everything set correctly in my androidmanifest.

find()方法只是始终返回null。没有意义的原因。

find() just always returns null. Doesn't make sense why.

推荐答案

我可以用下面的code得到以下结果。请尝试在后台方法查找。

I was able to get the following results using the following code. Please try the find in background method.

D /结果(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]

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();
                }
            }
        });

    }
}

这篇关于Parse.com find()方法返回null每次查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 20:17