Abhinav Tyagi Abhinav Tyagi - 4 months ago 65
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?


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);