How to create the smart store table in android using salesforce SDK

255 Views Asked by At

I am using the below source code from salesforce doc but its giving me a below error. How can i resolve it any one can help me.

   SmartStoreSDKManager sdkManager = SmartStoreSDKManager.getInstance();
   SmartStore mSmartStore = sdkManager.getSmartStore();


  private void createSoup() {

    IndexSpec[] ACCOUNTS_INDEX_SPEC = {
            new IndexSpec("Name",    SmartStore.Type.string),
            new IndexSpec("Id",      SmartStore.Type.string),
            new IndexSpec("OwnerId", SmartStore.Type.string)
    };
    mSmartStore.registerSoup(ACCOUNTS_SOUP, ACCOUNTS_INDEX_SPEC);
 }

When i am calling this method onCreate its showing me a below exception.

FATAL EXCEPTION: main Process: com.runtime, PID: 7033 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.runtime/com.runtime.activity.home.HomeActivity}: java.lang.ClassCastException: com.salesforce.androidsdk.app.SalesforceSDKManager cannot be cast to com.salesforce.androidsdk.smartstore.app.SmartStoreSDKManager at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2200) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2249) at android.app.ActivityThread.access$800(ActivityThread.java:141) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5052) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassCastException: com.salesforce.androidsdk.app.SalesforceSDKManager cannot be cast to com.salesforce.androidsdk.smartstore.app.SmartStoreSDKManager at com.salesforce.androidsdk.smartstore.app.SmartStoreSDKManager.getInstance(SmartStoreSDKManager.java:132) at com.runtime.activity.home.HomeActivity.setDefualtConfiguration(HomeActivity.java:163) at com.runtime.activity.home.HomeActivity.onCreate(HomeActivity.java:82) at android.app.Activity.performCreate(Activity.java:5242) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2249)  at android.app.ActivityThread.access$800(ActivityThread.java:141)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:136)  at android.app.ActivityThread.main(ActivityThread.java:5052)  at java.lang.reflect.Method.invokeNative(Native Method)

1

There are 1 best solutions below

9
mobility On

After lot of document read i found the solutions.

in my app file onCreate method just do this changes.

  //SalesforceSDKManager.initNative(getApplicationContext(), new NativeKeyImpl(), SplashActivity.class);

  Comment the above line of code and put this line of code.

  SmartSyncSDKManager.initNative(getApplicationContext(), new NativeKeyImpl(), SplashActivity.class);

   This line of code initialise smartstore SDK. The problem is soved