【问题标题】:Invalid Key PB: no elements无效的密钥 PB:没有元素
【发布时间】:2015-06-30 11:57:10
【问题描述】:

对于我的 android 应用,我正在为后端编写端点代码。

在我的 appengine 数据存储方法中,当我尝试使用密钥访问我的实体时,我得到

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

以下是我尝试过的代码sn-ps

Key key = KeyFactory.stringToKey(keyId);

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

keyId 是字符串类型。

如何解决?

【问题讨论】:

    标签: java android google-app-engine android-studio google-cloud-datastore


    【解决方案1】:

    自己解决了这个问题!
    我没有使用 stringToKey,而是使用 createKey 作为我想要的类型。
    将密钥作为字符串传递

     Key key = KeyFactory.createKey(<KIND>,keyId);
    

    【讨论】:

      【解决方案2】:

      试试这个代码:

      key = KeyFactory.stringToKey(""+keyId);
      

      【讨论】:

      • 我会尝试,但是这将如何帮助 keyId 已经是一个字符串?
      猜你喜欢
      • 2019-04-30
      • 1970-01-01
      • 1970-01-01
      • 2017-12-02
      • 2023-03-20
      • 2017-03-01
      • 2016-04-10
      • 1970-01-01
      • 2020-10-13
      相关资源
      最近更新 更多