解析 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[=11=]0(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.done(ParseQueryAdapter.java:393)
at com.parse.ParseQueryAdapter.done(ParseQueryAdapter.java:385)
at com.parse.ParseTaskUtils.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);
}
我似乎无法让本地数据存储与 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[=11=]0(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.done(ParseQueryAdapter.java:393)
at com.parse.ParseQueryAdapter.done(ParseQueryAdapter.java:385)
at com.parse.ParseTaskUtils.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);
}