![](/img/trans.png)
[英]JSONSTORE Mobilefirst 7.1 error java.lang.NoClassDefFoundError: com.worklight.jsonstore.util.JSONStoreUtil
[英]MobileFirst Platform JSONStore An error occurred when reading from the database
IBM MobileFirst版本:6.3移動操作系統:Android 4.4.4
我有一個用例,我們需要在集合內的單個文檔中存儲一個或多個base64編碼的圖像字符串。 (由於用例的性質,無法將圖像拆分為一個集合中的多個文檔)
將多達7個base64編碼的圖像字符串存儲到同一文檔中可以正常工作。 (將具有7個base64字符串圖像的文檔添加到JSONStore)。 將具有8個base64編碼的字符串圖像的文檔添加到集合中的同一文檔中時。 該文檔已成功添加到集合中。 但是,在集合上調用findAll()時(它僅包含1個文檔,帶有8個base64編碼的圖像;在這種情況下,需要findAll(),因為在該數據存在時,不存在用於填充搜索字段的數據從收藏中獲取); 發生以下錯誤:
Java:
E/JSONSTORE(24451): JSONStoreLogger.logError in JSONStoreLogger.java:189 :: Error when attempting to find a document. An error occurred when reading from the database.
E/JSONSTORE(24451): com.worklight.jsonstore.exceptions.JSONStoreFindException: Error when attempting to find a document. An error occurred when reading from the database.
E/JSONSTORE(24451): at com.worklight.jsonstore.api.JSONStoreCollection.findDocuments(JSONStoreCollection.java:896)
E/JSONSTORE(24451): at com.worklight.androidgap.jsonstore.dispatchers.FindActionDispatcher.databaseActionDispatch(FindActionDispatcher.java:117)
E/JSONSTORE(24451): at com.worklight.androidgap.jsonstore.dispatchers.BaseDatabaseActionDispatcher.actionDispatch(BaseDatabaseActionDispatcher.java:36)
E/JSONSTORE(24451): at com.worklight.androidgap.jsonstore.dispatchers.BaseActionDispatcher.dispatch(BaseActionDispatcher.java:90)
E/JSONSTORE(24451): at com.worklight.androidgap.plugin.DispatchingPlugin$ActionDispatcherRunnable.run(DispatchingPlugin.java:79)
E/JSONSTORE(24451): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
E/JSONSTORE(24451): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
E/JSONSTORE(24451): at java.lang.Thread.run(Thread.java:841)
E/JSONSTORE(24451): Caused by: java.lang.IllegalStateException: get field slot from row 0 col 0 failed
E/JSONSTORE(24451): at net.sqlcipher.CursorWindow.getLong_native(Native Method)
E/JSONSTORE(24451): at net.sqlcipher.CursorWindow.getLong(CursorWindow.java:381)
E/JSONSTORE(24451): at net.sqlcipher.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:110)
E/JSONSTORE(24451): at net.sqlcipher.AbstractCursor.moveToPosition(AbstractCursor.java:195)
E/JSONSTORE(24451): at net.sqlcipher.AbstractCursor.moveToNext(AbstractCursor.java:257)
E/JSONSTORE(24451): at android.database.CursorWrapper.moveToNext(CursorWrapper.java:166)
E/JSONSTORE(24451): at com.worklight.jsonstore.api.JSONStoreCollection.findDocuments(JSONStoreCollection.java:877)
E/JSONSTORE(24451): ... 7 more
E/JSONSTORE(24451): JSONStoreLogger.logError in JSONStoreLogger.java:189 :: error while executing find query on database "tempCollection"com.worklight.jsonstore.exceptions.JSONStoreFindException: Error when attempting to find a document. An error occurred when reading from the database.
E/JSONSTORE(24451): com.worklight.jsonstore.exceptions.JSONStoreFindException: Error when attempting to find a document. An error occurred when reading from the database.
E/JSONSTORE(24451): at com.worklight.jsonstore.api.JSONStoreCollection.findDocuments(JSONStoreCollection.java:896)
E/JSONSTORE(24451): at com.worklight.androidgap.jsonstore.dispatchers.FindActionDispatcher.databaseActionDispatch(FindActionDispatcher.java:117)
E/JSONSTORE(24451): at com.worklight.androidgap.jsonstore.dispatchers.BaseDatabaseActionDispatcher.actionDispatch(BaseDatabaseActionDispatcher.java:36)
E/JSONSTORE(24451): at com.worklight.androidgap.jsonstore.dispatchers.BaseActionDispatcher.dispatch(BaseActionDispatcher.java:90)
E/JSONSTORE(24451): at com.worklight.androidgap.plugin.DispatchingPlugin$ActionDispatcherRunnable.run(DispatchingPlugin.java:79)
E/JSONSTORE(24451): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
E/JSONSTORE(24451): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
E/JSONSTORE(24451): at java.lang.Thread.run(Thread.java:841)
E/JSONSTORE(24451): Caused by: java.lang.IllegalStateException: get field slot from row 0 col 0 failed
E/JSONSTORE(24451): at net.sqlcipher.CursorWindow.getLong_native(Native Method)
E/JSONSTORE(24451): at net.sqlcipher.CursorWindow.getLong(CursorWindow.java:381)
E/JSONSTORE(24451): at net.sqlcipher.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:110)
E/JSONSTORE(24451): at net.sqlcipher.AbstractCursor.moveToPosition(AbstractCursor.java:195)
E/JSONSTORE(24451): at net.sqlcipher.AbstractCursor.moveToNext(AbstractCursor.java:257)
E/JSONSTORE(24451): at android.database.CursorWrapper.moveToNext(CursorWrapper.java:166)
E/JSONSTORE(24451): at com.worklight.jsonstore.api.JSONStoreCollection.findDocuments(JSONStoreCollection.java:877)
E/JSONSTORE(24451): ... 7 more
E/wl.jsonstore(24451): {"src":"find","err":22,"msg":"INVALID_SEARCH_FIELD","col":"tempCollection","usr":"testUser","doc":{},"res":{}}
Javascript:
{"src":"findAll","err":22,"msg":"INVALID_SEARCH_FIELD","col":"tempCollection","usr":"testUser","doc":{},"res":{}}
我做錯了什么,還是我濫用了?
編輯:
在里面:
var storeDetails = {
collections: {
tempCollection: {}
},
options: {
username: 'ausername',
password: 'apassword',
localKeyGen: true //Optional local key generation flag, default false.
}
};
WL.JSONStore.init(storeDetails.collections, storeDetails.options);
找到所有:
var options = {
limit: 1
};
WL.JSONStore.get('tempCollection').findAll(options);
Base64編碼的圖像字符串:我正在使用Cordova相機API(Worklight / MF附帶)。 代碼片段:通過使用Camera.DestinationType.DATA_URL,將圖像作為base64編碼的字符串返回。
var options = {
quality: 100,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
encodingType: Camera.EncodingType.PNG,
targetWidth: 500,
targetHeight: 500,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: true,
cameraDirection: Camera.Direction.BACK
};
navigator.camera.getPicture(function (imageData) {
var doc = {
src: imageData;
};
WL.JSONStore.get('tempCollection').add(doc);
}, function (err) {
}, options);
我能夠重現您的問題。 在JSON文檔中將某些圖像添加為單個數組的一部分后,出現了與您所呈現的錯誤相同的錯誤。 而且,在您顯示錯誤之前,我可以看到另外一個
05-04 20:27:38.934: E/CursorWindow(32148): need to grow: mSize = 1048576, size = 1107180, freeSpace() = 1048482, numRows = 1
05-04 20:27:38.934: E/CursorWindow(32148): Attempting to grow window beyond max size (1048576)
05-04 20:27:38.934: E/Cursor(32148): Failed allocating 1107180 bytes for text/blob at 0,1
05-04 20:27:38.935: D/Cursor(32148): finish_program_and_get_row_count row 0
05-04 20:27:39.151: E/CursorWindow(32148): need to grow: mSize = 1048576, size = 1107180, freeSpace() = 1048482, numRows = 1
05-04 20:27:39.151: E/CursorWindow(32148): Attempting to grow window beyond max size (1048576)
05-04 20:27:39.151: E/Cursor(32148): Failed allocating 1107180 bytes for text/blob at 0,1
05-04 20:27:39.152: D/Cursor(32148): finish_program_and_get_row_count row 0
05-04 20:27:39.152: E/CursorWindow(32148): Bad request for field slot 0,0. numRows = 0, numColumns = 2
因此,我的猜測是您正在強調設備內存的限制。
當您將多個圖片添加到單個JSON文檔時,您將創建一個巨大的JSON文檔。 然后,當您搜索它時,可能有某種類型的解析操作或類似的操作需要將整個JSON分配在內存中。 findAll本身的結果將包含該巨大的json文檔。 可能需要使用連續的內存分配。
問題是單個Android應用程序可用的內存總量有限。 實際值取決於設備制造商。 它不一定與設備的“高端”程度或設備中可用的總內存有關。 一些制造商可能會創建具有2GB內存但每個應用程序只有幾個MB可用空間的設備,因此他們優先考慮保持多個應用程序並行運行的能力,而不是少數應用程序占用所有資源。
最后,我的建議是,您實際上應該將每個圖像存儲在一個獨立的JSON文檔中。 您可能只有一個包含ID數組的文檔,並且圖像存儲在第二個集合中,或者是其他一些替代解決方案。
另請注意,這不是JSONStore的限制,而是Android平台施加的限制。 永遠不允許單個應用程序單獨消耗所有內存資源,它始終限於MB。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.