简体   繁体   English

Android解析:本地数据存储和ParseQueryAdapter不兼容?

[英]Parse for Android: Local Datastore and ParseQueryAdapter incompatible?

I can't seem to get the local datastore work together with the ParseQueryAdapter. 我似乎无法将本地数据存储与ParseQueryAdapter一起使用。 Even if I try to run the official test app OfflineTodos at https://github.com/ParsePlatform/OfflineTodos . 即使我尝试在https://github.com/ParsePlatform/OfflineTodos上运行官方测试应用程序OfflineTodos。

Anyone else with this problem who was able to solve it? 有这个问题的其他人能够解决吗?

This is my stacktrace: 这是我的堆栈跟踪:

09-07 14:24:06.871    6366-6366/nl.abc.parsetest E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: Unsupported method when Local Datastore is enabled.
        at com.parse.ParseQuery.throwIfLDSEnabled(ParseQuery.java:291)
        at com.parse.ParseQuery.throwIfLDSEnabled(ParseQuery.java:277)
        at com.parse.ParseQuery.access$000(ParseQuery.java:89)
        at com.parse.ParseQuery$State$Builder.getCachePolicy(ParseQuery.java:660)
        at com.parse.ParseQuery.getCachePolicy(ParseQuery.java:1021)
        at com.parse.ParseQueryAdapter$3.done(ParseQueryAdapter.java:393)
        at com.parse.ParseQueryAdapter$3.done(ParseQueryAdapter.java:385)
        at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:115)
        at android.os.Handler.handleCallback(Handler.java:725)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5041)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
        at dalvik.system.NativeStart.main(Native Method)
09-07 14:24:08.363    6366-6366/? I/Process﹕ Sending signal. PID: 6366 SIG: 9

For completeness, my query: 为了完整性,我的查询是:

    ParseQueryAdapter.QueryFactory<Todo> factory = new ParseQueryAdapter.QueryFactory<Todo>() {
        public ParseQuery<Todo> create() {
            ParseQuery<Todo> query = Todo.getQuery();
            query.orderByDescending("createdAt");
            query.fromLocalDatastore();
            return query;
        }
    };
    // Set up the adapter
    inflater = (LayoutInflater) this
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    todoListAdapter = new ToDoListAdapter(this, factory);

And the simple adapter: 和简单的适配器:

private class ToDoListAdapter extends ParseQueryAdapter<Todo> {

    public ToDoListAdapter(Context context,
                           ParseQueryAdapter.QueryFactory<Todo> queryFactory) {
        super(context, queryFactory);
    }

    @Override
    public View getItemView(Todo todo, View view, ViewGroup parent) {
        ViewHolder holder;
        if (view == null) {
            view = inflater.inflate(R.layout.list_item_todo, parent, false);
            holder = new ViewHolder();
            holder.todoTitle = (TextView) view
                    .findViewById(R.id.todo_title);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        TextView todoTitle = holder.todoTitle;
        todoTitle.setText(todo.getTitle());
        if (todo.isDraft()) {
            todoTitle.setTypeface(null, Typeface.ITALIC);
        } else {
            todoTitle.setTypeface(null, Typeface.NORMAL);
        }
        return view;
    }
}

private static class ViewHolder {
    TextView todoTitle;
}

Looks like a fairly recent commit broke it. 看起来好像是最近一次提交破坏了它。 Try adding the Parse.isLocalDataStoreEnabled() to this line in ParseQueryAdapter.java to fix 尝试将Parse.isLocalDataStoreEnabled()添加到ParseQueryAdapter.java中的此行以进行修复

    // In the case of CACHE_THEN_NETWORK, two callbacks will be called. We can only remove the
    // query after the second callback.
    if (Parse.isLocalDatastoreEnabled() || query.getCachePolicy() != CachePolicy.CACHE_THEN_NETWORK ||
            (query.getCachePolicy() == CachePolicy.CACHE_THEN_NETWORK && !firstCallBack.get())) {
      runningQueries.remove(query);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM