I have a bunch of data stored in Kinvey that I wish is access via a mobile app in Android. I have managed to do a Ping and implicit User login correctly but when trying to access my data it doesn't work. Below is my JobsEntity class that has objects set up for some but not all of the fields of data contained in the collection on Kinvey:
Hey, Can you post the entire stacktrace for the error? It looks like what is above is missing the first couple lines, and I am going to need all of that red text in logcat to figure out what the issue might be.
over 8 years ago
That is the full stack trace from the LogCat in Android Studio, but here it is again:
12-05 17:48:32.265 17863-17863/com.osgs.app V/Kinvey - Client﹕ adding new instance of AppData, new collection name
12-05 17:48:32.265 17863-17884/com.osgs.app W/System.err﹕ at com.kinvey.java.core.KinveyClientRequestInitializer.initialize(KinveyClientRequestInitializer.java:98)
12-05 17:48:32.265 17863-17884/com.osgs.app W/System.err﹕ at com.kinvey.java.core.AbstractKinveyClient.initializeRequest(AbstractKinveyClient.java:140)
12-05 17:48:32.265 17863-17884/com.osgs.app W/System.err﹕ at com.kinvey.java.AbstractClient.initializeRequest(AbstractClient.java:186)
12-05 17:48:32.265 17863-17884/com.osgs.app W/System.err﹕ at com.kinvey.java.User.retrieveBlocking(User.java:380)
12-05 17:48:32.265 17863-17884/com.osgs.app W/System.err﹕ at com.kinvey.java.User.retrieveMetadataBlocking(User.java:234)
12-05 17:48:32.265 17863-17884/com.osgs.app W/System.err﹕ at com.kinvey.android.AsyncUser$RetrieveMetaData.executeAsync(AsyncUser.java:935)
12-05 17:48:32.265 17863-17884/com.osgs.app W/System.err﹕ at com.kinvey.android.AsyncUser$RetrieveMetaData.executeAsync(AsyncUser.java:927)
12-05 17:48:32.265 17863-17884/com.osgs.app W/System.err﹕ at com.kinvey.android.AsyncClientRequest.doInBackground(AsyncClientRequest.java:65)
12-05 17:48:32.265 17863-17884/com.osgs.app W/System.err﹕ at com.kinvey.android.AsyncClientRequest$KinveySerialExecutor$1.run(AsyncClientRequest.java:128)
I have done further testing on this and it seems to be something to do with the delay in time it takes to pull back all of the data from Kinvey as there are over 400 objects. Again the code I am using to call the Kinvey backend for the data and store it in my class is:
Now say I run this app inside Android Studio in debug mode and add a watch to "myevents" when the app loads up this is empty so there are no results variables yet. After about 5 sec the "myevents" updates and now states "No such instance field: 'val$myevents' " however the results variable for the page is now full of the data from Kinvey.
I do not know why the GET function doesn't seem to wait for the call to be finished before moving on as this seems to be the problem. Is there a certain way I need to make the call for all objects? Do I have to do the call in a separate function as I am calling it in the onCreate atm?
over 8 years ago
Hey, our android library provides asynchronous methods-- that means that all service requests are run in their own AsyncTask, and will take time to complete. You can use the callbacks to get notified when a request is complete, no matter how long it takes--
It looks like the problem here is that the GET request is being executed before the login request completes. Can you also double check that you are using the latest version of the library?
Basically, you will want to do this:
myClient = new Client.Builder(...).build();
//Right here, `u` is the currently logged in user
note that login has to complete before any other request can be executed, so if you put the transition away from login in the `onSuccess` method of that login's KinveyUserCallback, you shouldn't have to worry about the timing.