二进制数据,对象引用和RealmList

时间:2016-10-18 21:51:18

标签: java realm

我在Android应用程序中使用Realm。我有下一个问题:

  E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
              Process: ec.com.se.demo.android.priceList, PID: 3557
              java.lang.RuntimeException: An error occured while executing doInBackground()
                  at android.os.AsyncTask$3.done(AsyncTask.java:300)
                  at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
                  at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
                  at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
                  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                  at java.lang.Thread.run(Thread.java:841)
               Caused by: java.lang.IllegalArgumentException: Illegal Argument: Sort is not supported on binary data, object references and RealmList.
                  at io.realm.internal.TableView.nativeSortMulti(Native Method)
                  at io.realm.internal.TableView.sort(TableView.java:665)
                  at io.realm.RealmQuery.findAllSorted(RealmQuery.java:1913)
                  at ec.com.se.demo.android.priceList.util.Queries.filterScrollData(Queries.java:68)
                  at ec.com.se.demo.android.priceList.tasks.FetchRowsTask.doInBackground(FetchRowsTask.java:51)
                  at ec.com.se.demo.android.priceList.tasks.FetchRowsTask.doInBackground(FetchRowsTask.java:21)
                  at android.os.AsyncTask$2.call(AsyncTask.java:288)
                  at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
                  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
                  at java.lang.Thread.run(Thread.java:841) 

我的代码是下一个:

public static ArrayList<Producto> filterScrollData(Integer initialPosition, Integer finalPosition, List<Tag> tags, final MainActivity main){
    ArrayList<Producto> result = new ArrayList<>();
    RealmQuery query = buscar(tags);
    RealmResults results= query.findAllSorted(new String[]{"tipo", "categoria", "proveedor", "nombre"}, new Sort[]{Sort.ASCENDING,Sort.ASCENDING, Sort.ASCENDING, Sort.ASCENDING});
    if(initialPosition + 7 < query.count()){
        Iterator<Producto> iterator = results.subList(initialPosition, finalPosition).iterator();
        while (iterator.hasNext()) result.add(new Producto(iterator.next()));
    }else{
        int aux=query.findAll().size();
        Iterator<Producto> iterator = results.subList(initialPosition, query.findAll().size()).iterator();
        while (iterator.hasNext()) result.add(new Producto(iterator.next()));
        main.runOnUiThread(new Runnable() {
            public void run() {
                Toast.makeText(main, "No existen mas registros", Toast.LENGTH_SHORT).show();
            }
        });
    }
    return result;
}

我想返回一个已排序的对象列表,我正在查看Realm官方文档,findAllSorted()方法接收一个String列表作为参数,这些字段是字段名称和Sort

列表

0 个答案:

没有答案