Abhinav Tyagi Abhinav Tyagi - 1 year ago 174
Java Question

Invalid Key PB: no elements

For my android app I am writing endpoints code for backend.

In my appengine datastore method, when I try to access my Entity using key, I get

java.lang.IllegalArgumentException: Invalid Key PB: no elements

following are code snippets I have tried out

Key key = KeyFactory.stringToKey(keyId);

key = KeyFactory.stringToKey(URLEncoder.encode(keyId, "utf-8"));

keyId is of type String.

How to resolve this?

Answer Source

Resolved the issue myself!
Instead of using stringToKey I used createKey for the KIND I want.
Passed the key as String

 Key key = KeyFactory.createKey(<KIND>,keyId);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download