如何检查ParseQuery对象的总数?

时间:2014-01-23 09:26:55

标签: java android listview parse-platform

我有一个加载更多的ListView,我想检查当前列表是否等于我班级中ParseQuery对象的总数。

我试过

try {
    query.count();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
    }

但它迫使我的应用程序崩溃。

你知道如何实现这个目标吗?

public void updateData() {
         mListView = (ListView)getView().findViewById(R.id.animal_list);     
   final ParseQuery<Animal> query = ParseQuery.getQuery(Animal.class);
    query.setCachePolicy(CachePolicy.NETWORK_ELSE_CACHE);
    query.orderByAscending("animal");

    query.setLimit(mListView.getCount() + 5);



    query.findInBackground(new FindCallback<Animal>() {

        @Override
          public void done(List<Animal> animals, ParseException error) {

              if(animals != null){
                  mAdapter.clear();


               mProgressBar.setVisibility(View.INVISIBLE);
              for (int i = 0; i > animals.size(); i++) {



                      mAdapter.add(animals.get(i));

                      if(animals.size() > 20){ //here

                      //I've set it manually with hard-coded num. 20

                        query.cancel();
                        RelativeLayout footie = (RelativeLayout) getView().findViewById(R.id.footerview);   
                        mListView.removeFooterView(footie);
                      } 

                  }  
              }  
            }
         }); 
    } 

我的LogCat:

01-23 10:59:46.619: E/AndroidRuntime(16659): FATAL EXCEPTION: AsyncTask #1
01-23 10:59:46.619: E/AndroidRuntime(16659): java.lang.RuntimeException: An error occured while executing doInBackground()
01-23 10:59:46.619: E/AndroidRuntime(16659):    at android.os.AsyncTask$3.done(AsyncTask.java:200)
01-23 10:59:46.619: E/AndroidRuntime(16659):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
01-23 10:59:46.619: E/AndroidRuntime(16659):    at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
01-23 10:59:46.619: E/AndroidRuntime(16659):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
01-23 10:59:46.619: E/AndroidRuntime(16659):    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
01-23 10:59:46.619: E/AndroidRuntime(16659):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
01-23 10:59:46.619: E/AndroidRuntime(16659):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
01-23 10:59:46.619: E/AndroidRuntime(16659):    at java.lang.Thread.run(Thread.java:1027)
01-23 10:59:46.619: E/AndroidRuntime(16659): Caused by: java.lang.NullPointerException
01-23 10:59:46.619: E/AndroidRuntime(16659):    at com.example.animalist.Fragment1.updateData(Fragment1.java:73)
01-23 10:59:46.619: E/AndroidRuntime(16659):    at com.example.animalist.Fragment1$RemoteDataTask.doInBackground(Fragment1.java:127)
01-23 10:59:46.619: E/AndroidRuntime(16659):    at com.example.animalist.Fragment1$RemoteDataTask.doInBackground(Fragment1.java:1)
01-23 10:59:46.619: E/AndroidRuntime(16659):    at android.os.AsyncTask$2.call(AsyncTask.java:185)
01-23 10:59:46.619: E/AndroidRuntime(16659):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
01-23 10:59:46.619: E/AndroidRuntime(16659):    ... 4 more

0 个答案:

没有答案