Start a new topic

getTypedObject doesn't work.

I tried to use getTypedObject as suggested in this comment:

but it is not working with ArrayList.

The getTypedObject always return null !

In order to verify my code I include a test code in of the Kinvey StatusShare Example:

public void populateViews(){

if (entity.getThumbnail() != null){







List commentRefs = entity.getComments();

if (commentRefs == null){



//***** included test *****

CommentEntity mycomment = commentRefs.get(0).getTypedObject(CommentEntity.class);

//***** included test END ***** => my comment always null

List comments = new ArrayList();

for (KinveyReference kr : commentRefs){



CommentAdapter adapter = new CommentAdapter(getSherlockActivity(), comments, getSherlockActivity().getLayoutInflater());



Always return null from getTypedObject



Can you post the code you use to perform the GET operation on AppData? There are a couple variations of this method, and that might be where the issue is.

I added the getTypedObject in the StatusShareActivity example from Kinvey, in the file. So I believe the code that performed the GET is

private void loadUpdates() {


Query q = getClient().appData(StatusShare.COL_UPDATES, UpdateEntity.class).query();


q.addSort("_kmd.lmt", AbstractQuery.SortOrder.DESC);

getClient().linkedData(StatusShare.COL_UPDATES, UpdateEntity.class).get(q, new KinveyListCallback() {


public void onSuccess(UpdateEntity[] result) {

android.util.Log.d(Client.TAG, "Count of updates found: " + result.length);

for (UpdateEntity e : result) {

Log.d(Client.TAG, "result -> " + e.toString());


if (getSherlockActivity() == null){



((StatusShare)getSherlockActivity()).setShareList(new ArrayList());


if ( ((StatusShare)getSherlockActivity()).getShareList().size() == 0){



} else{






public void onFailure(Throwable error) {

Log.w(Client.TAG, "Error fetching updates data: " + error.getMessage());



}, null, new String[]{"author", "comments", "author"}, 3, true);

So there are two reasons this method could return null.

First, can you confirm that the reference i resolved? It cannot be cast to a `CommentEntity` if it is null in the first place, and instead of crashing the library will just return null.

A quick way to test this is to add this line right before your test:

Log.i("my app", "is it null -> " + (commentRefs.get(0).get("_obj") == null));

that will log true if the `_obj` field of the `KinveyReference` object is null, which means it hasn't been resolved. If the above that is the case, let me know because the issue might be elsewhere.

If you do see a `false` logged, can you also look for the message:

"unable to instantiate class!"

That will be logged if there is an issue with the JSON parser, which also would be caught and return a null.

Here are the answers

04-10 17:25:47.936: I/my app(15235): is it null -> false

04-10 17:25:47.967: I/System.out(15235): unable to instantiate class!

OK, good-- so the issue is that it cannot create a `CommentEntity`.

below that log line, `unable to instantiate class!`, there should be a red stacktrace. If there is, can you paste that as well?
Here you are

04-10 17:25:47.971: W/System.err(15235): at

04-10 17:25:47.971: W/System.err(15235): at

04-10 17:25:47.975: W/System.err(15235): at

04-10 17:25:47.975: W/System.err(15235): at

04-10 17:25:47.975: W/System.err(15235): at com.kinvey.samples.statusshare.fragments.UpdateDetailsFragment.populateViews(

04-10 17:25:47.975: W/System.err(15235): at com.kinvey.samples.statusshare.fragments.KinveyFragment.onResume(

04-10 17:25:47.975: W/System.err(15235): at

04-10 17:25:47.979: W/System.err(15235): at

04-10 17:25:47.979: W/System.err(15235): at

04-10 17:25:47.979: W/System.err(15235): at

04-10 17:25:47.979: W/System.err(15235): at$

04-10 17:25:47.982: W/System.err(15235): at android.os.Handler.handleCallback(

04-10 17:25:47.982: W/System.err(15235): at android.os.Handler.dispatchMessage(

04-10 17:25:47.982: W/System.err(15235): at android.os.Looper.loop(

04-10 17:25:47.982: W/System.err(15235): at

04-10 17:25:47.982: W/System.err(15235): at java.lang.reflect.Method.invokeNative(Native Method)

04-10 17:25:47.986: W/System.err(15235): at java.lang.reflect.Method.invoke(

04-10 17:25:47.986: W/System.err(15235): at$

04-10 17:25:47.986: W/System.err(15235): at

04-10 17:25:47.986: W/System.err(15235): at dalvik.system.NativeStart.main(Native Method)

04-10 17:25:50.084: I/StatusBarPolicy(216): BAT. S:2 H:2

04-10 17:25:50.607: W/PowerManagerService(132): Timer 0x3->0x3|0x0

04-10 17:26:00.092: I/StatusBarPolicy(216): BAT. S:2 H:2

04-10 17:26:00.217: I/StatusBarPolicy(216): onSignalStrengthsChanged


Do you need more information to find the cause of this issue?

That is an issue with typing-- it looks like `GenericJson` is unable to set a Field, which fails because the expected class doesn't match the actual class. For example, if your `GenericJson` has a `private String userID`, but the value of that is an integer in your backend, JSON deserialization will fail.

All that method does is instantiate a new instance of whatever class is provided, grab every name/value pair within the JSON object, and set it on that new object that was created.

Can you log `commentRefs.get(0)`, and ensure there is a field "_obj", containing a CommentEntity and that the types are what is expected?

Hello, I have the same problem with getTypedObject returning null here:

     BookCloud c =;

The problem only appears when I add an integer or float field, If I remove that field then works fine. I also can see the correct values in the kinveyreference "obj" field retrieved.

Here is the BookCloud class with an integer "pages" field added:

public class BookCloud extends extends GenericJson {

 @Key private String title;

 @Key private String edition;

 @Key private int pages;

 public BookCloud() {


Can you help me?


Login or Signup to post a comment