我似乎无法让本地数据存储与 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;
}