MobileFirst 7.1 - 在Android上部署JSONStore Hybrid App时出现问题

时间:2016-01-08 19:21:18

标签: ibm-mobilefirst jsonstore

我正在尝试将JSONStore用于其中一个要求。

由于它是混合应用程序,我通过以下配置 程序

使用应用程序描述符编辑器打开文件   application-descriptor.xml单击“设计”选项卡。在概述下,     展开应用程序[您的应用程序名称]。单击可选     特征。单击添加。选择JSONStore。单击确定。在项目中     在资源管理器视图中,右键单击标有您的文件夹     应用名称。单击运行方式。单击“在MobileFirst Development上运行”     服务器

以下是我用于在JSONStore中创建文档的示例代码。我按照documentation中的说明进行了操作。

WL.Logger.debug ("Successfully connected to MobileFirst Server.");

    var collectionName = 'SomeFlag';

    if(WL.JSONStore.get(collectionName) == null && WL.JSONStore.get(collectionName) == undefined){      
        // Object that defines all the collections.
        var collections = {

          // Object that defines the 'people' collection.
                userAgreement : {

            // Object that defines the Search Fields for the 'people' collection.
            searchFields : {someFlag: 'boolean'}
          }
        };

        // Optional options object.
        var options = {
          localKeyGen : false
        };

        WL.JSONStore.init(collections, options)

        .then(function () {
          var data = [{someFlag: false}];

          // Optional options for add.
          var addOptions = {

            // Mark data as dirty (true = yes, false = no), default true.
            markDirty: true
          };

          // Get an accessor to the people collection and add data.
          return WL.JSONStore.get(collectionName).add(data, addOptions);
        })

        .then(function (numberOfDocumentsAdded) {
            WL.Logger.debug ("Number Of Documents Added " +numberOfDocumentsAdded);
            alert ("Number Of Documents Added " +numberOfDocumentsAdded);
          // Add was successful.
        })

        .fail(function (errorObject) {
           // Handle failure for any of the previous JSONStore operations (init, add).
            WL.Logger.debug ("JSONStore Failed to add any document errorObject " +errorObject);
        });
    }

在Android中运行时,JSONStore创建失败。

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/worklight/jsonstore/util/JSONStoreUtil;
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at com.worklight.androidgap.jsonstore.dispatchers.BaseActionDispatcher.<init>(BaseActionDispatcher.java:44)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at com.worklight.androidgap.jsonstore.dispatchers.BaseDatabaseActionDispatcher.<init>(BaseDatabaseActionDispatcher.java:29)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at com.worklight.androidgap.jsonstore.dispatchers.AllDirtyActionDispatcher.<init>(AllDirtyActionDispatcher.java:36)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at com.worklight.androidgap.plugin.StoragePlugin.initialize(StoragePlugin.java:59)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at org.apache.cordova.CordovaPlugin.privateInitialize(CordovaPlugin.java:50)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:195)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at org.apache.cordova.PluginManager.exec(PluginManager.java:141)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:61)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:40)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:37)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at android.os.Looper.loop(Looper.java:135)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at android.os.HandlerThread.run(HandlerThread.java:61)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.worklight.jsonstore.util.JSONStoreUtil" on path: DexPathList[[zip file "/data/app/com.DCSSMobileApp-2/base.apk"],nativeLibraryDirectories=[/data/app/com.DCSSMobileApp-2/lib/arm, /vendor/lib, /system/lib]]
    01-08 13:34:03.964 12289-12425/com.DCSSMobileApp W/System.err:     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    01-08 13:34:03.964 12289-12425/com.DCSSMobileApp W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    01-08 13:34:03.964 12289-12425/com.DCSSMobileApp W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    01-08 13:34:03.964 12289-12425/com.DCSSMobileApp W/System.err:  ... 14 more
    01-08 13:34:03.964 12289-12425/com.DCSSMobileApp W/System.err:  Suppressed: java.lang.ClassNotFoundException: com.worklight.jsonstore.util.JSONStoreUtil
    01-08 13:34:03.965 12289-12425/com.DCSSMobileApp W/System.err:     at java.lang.Class.classForName(Native Method)
    01-08 13:34:03.965 12289-12425/com.DCSSMobileApp W/System.err:     at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
    01-08 13:34:03.965 12289-12425/com.DCSSMobileApp W/System.err:     at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
    01-08 13:34:03.965 12289-12425/com.DCSSMobileApp W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
    01-08 13:34:03.965 12289-12425/com.DCSSMobileApp W/System.err:      ... 15 more
    01-08 13:34:03.965 12289-12425/com.DCSSMobileApp W/System.err:  Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

2 个答案:

答案 0 :(得分:0)

我正在使用与评论中提到的相同的构建,并且能够成功运行JSONStore,而不会遇到此错误。

  1. 创建新的混合应用并添加了Android环境
  2. 添加了JSONStore可选功能
  3. 共同添加以下代码/ js / main.js&gt; wlCommonInit()

    function wlCommonInit(){
        var collectionName = 'people';
    
        // Object that defines all the collections.
        var collections = {
            // Object that defines the 'people' collection.
            people : {
                // Object that defines the Search Fields for the 'people' collection.
               searchFields : {name: 'string', age: 'integer'}
            }
        };
    
        // Optional options object.
        var options = {
            // Optional username, default 'jsonstore'.
            username : 'carlos',
    
            // Optional password, default no password.
            password : '123',
    
            // Optional local key generation flag, default false.
            localKeyGen : false
        };
    
        WL.JSONStore.init(collections, options)
    
        .then(function () {
            alert ("success");
        });
    }
    
  4. 我在Android模拟器中启动了应用程序并显示了警告。

答案 1 :(得分:0)

终于搞定了。我发现jsonstore.jar没有包含在我的Android项目库中,这导致了这个错误。