parse-community / ParseUI-Android

ParseUI contains user interface libraries for building apps with the Parse Android SDK.
Other
592 stars 324 forks source link

ParseQueryAdapter Error When Local Datastore and CachePolicy Enabled #123

Open ayublin opened 8 years ago

ayublin commented 8 years ago

Hello, I am getting a fatal error when enabling local datastore:

    Parse.enableLocalDatastore(this);
    Parse.initialize(this);

And setting cache policy on my ParseQuery object under ParseQueryAdapter:

    public ServerAdapter(Context context) {
        super(context, new QueryFactory() {
            @Override
            public ParseQuery create() {
                ParseQuery query = new ParseQuery("Server");
                query.setCachePolicy(ParseQuery.CachePolicy.CACHE_ELSE_NETWORK);
                return query;
            }
        });
    }

Are they not supposed to be enabled together? I can't think of any reason why they shouldn't though.

Here is the error message:

Caused by: 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.setCachePolicy(ParseQuery.java:665)
  at com.parse.ParseQuery.setCachePolicy(ParseQuery.java:1013)
  at com.package.myapp.views.adapters.ServerAdapter$1.create(ServerAdapter.java:20)
  at com.parse.ParseQueryAdapter.loadObjects(ParseQueryAdapter.java:366)
  at com.parse.ParseQueryAdapter.loadObjects(ParseQueryAdapter.java:362)
  at com.parse.ParseQueryAdapter.registerDataSetObserver(ParseQueryAdapter.java:326)
  at android.widget.ListView.setAdapter(ListView.java:468)
  at com.package.myapp.MainActivity.onCreate(MainActivity.java:44)
  at android.app.Activity.performCreate(Activity.java:5133)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2225)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2311) 
  at android.app.ActivityThread.access$600(ActivityThread.java:149) 
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293) 
  at android.os.Handler.dispatchMessage(Handler.java:99) 
  at android.os.Looper.loop(Looper.java:137) 
  at android.app.ActivityThread.main(ActivityThread.java:5214) 
  at java.lang.reflect.Method.invokeNative(Native Method) 

The issue is similar to this SO thread: http://stackoverflow.com/q/32438838

grantland commented 8 years ago

You're correct, LDS and cache policies are not compatible with each other.