在Google应用引擎上保存长文本

时间:2014-06-15 13:48:47

标签: java android google-app-engine

我正在尝试在Google云数据存储区中保存一个长字符串(超过500个字符)。 我搜索了网络,发现我需要使用Text代替String,所以我试图这样做。

我改变了这个:

CloudEntity newProfilePicture = new CloudEntity("profiles");
newProfilePicture.put(MainMenu.userNickName, dataToSave);

到此:

CloudEntity newProfilePicture = new CloudEntity("profiles");
Text dataText = new Text(dataToSave);
newProfilePicture.put(MainMenu.userNickName, dataText);

但程序崩溃..

(如果我保存短字符串,一切正常)

注意 - 如果重要,我使用的Text的导入是:

com.google.appengine.api.datastore.Text

来自我下载的 jar (否则,eclipse无法识别Text类型)

logcat:

06-15 16:36:49.710: E/AndroidRuntime(31005): FATAL EXCEPTION: Thread-3184
06-15 16:36:49.710: E/AndroidRuntime(31005): java.lang.NullPointerException
06-15 16:36:49.710: E/AndroidRuntime(31005):    at java.util.HashMap.putAll(HashMap.java:507)
06-15 16:36:49.710: E/AndroidRuntime(31005):    at com.google.cloud.backend.core.CloudEntity.createCloudEntityFromEntityDto(CloudEntity.java:79)
06-15 16:36:49.710: E/AndroidRuntime(31005):    at com.google.cloud.backend.core.CloudBackend.insert(CloudBackend.java:111)
06-15 16:36:49.710: E/AndroidRuntime(31005):    at com.google.cloud.backend.core.CloudBackendAsync.access$0(CloudBackendAsync.java:1)
06-15 16:36:49.710: E/AndroidRuntime(31005):    at com.google.cloud.backend.core.CloudBackendAsync$1.callBackend(CloudBackendAsync.java:87)
06-15 16:36:49.710: E/AndroidRuntime(31005):    at com.google.cloud.backend.core.CloudBackendAsync$1.callBackend(CloudBackendAsync.java:1)
06-15 16:36:49.710: E/AndroidRuntime(31005):    at com.google.cloud.backend.core.CloudBackendAsync$BackendCaller.run(CloudBackendAsync.java:402)

有什么建议吗? 请帮忙! :o

2 个答案:

答案 0 :(得分:2)

来自:https://cloud.google.com/developers/articles/mobile-backend-starter-api-reference#cep

Text不是CloudEntity支持的数据类型。支持的数据类型包括:

String           Up to 500 Unicode characters
Integer          Converted to BigDecimal when reading the value from backend
Double/Float     Converted to BigDecimal when reading the value from backend
Boolean          With true or false values
DateTime         com.google.api.client.util.DateTime object. is converted to a String when reading the value from backend
List/Map         java.util.List or java.util. Map object that can contain strings longer than 500 characters and child List/Map. The elements are not indexed on Datastore and cannot be used as a query filtering/sorting condition. Empty List/Maps are not stored on Datastore
null

答案 1 :(得分:1)

您尝试将字节放入字符串中,如果要保存图像配置文件字节,请使用com.google.appengine.api.datastore.Blob而不是Text

无论如何,请阅读此文档以使数据存储更加舒适 https://developers.google.com/appengine/docs/java/datastore/entities