簡體   English   中英

Android解析:本地數據存儲和ParseQueryAdapter不兼容?

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

我似乎無法將本地數據存儲與ParseQueryAdapter一起使用。 即使我嘗試在https://github.com/ParsePlatform/OfflineTodos上運行官方測試應用程序OfflineTodos。

有這個問題的其他人能夠解決嗎?

這是我的堆棧跟蹤:

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

為了完整性,我的查詢是:

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

和簡單的適配器:

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

看起來好像是最近一次提交破壞了它。 嘗試將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