3

I am trying to get cookies in webview on shouldOverrideUrlLoading() method and i got this error. Please have a look at my code below,

WebViewClient loginClient = new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            CookieManager cookieManager = CookieManager.getInstance();
            final String cookie = cookieManager.getCookie(url);

            //Some Code after this
        }
 }

And i m getting this error,

java.lang.IllegalStateException: CookieSyncManager::createInstance() needs to be called before CookieSyncManager::getInstance()
Sivakumar S
  • 681
  • 5
  • 19

1 Answers1

1

Use CookieSyncManager.createInstance(this); in your Activity's onCreate() Method. The error clearly says createInstance() need to be called before calling getInstance().

Brijesh Thakur
  • 6,768
  • 4
  • 24
  • 29
  • 1
    I am also seeing the same error. I am calling CookieSyncManager.createInstance(this) in the onCreate method and CookieSyncManager.getInstance().startSync() in onResume and CookieSyncManager.getInstance().stopSync() in onPause. Still I see the same error sometimes – aasha Sep 17 '13 at 06:28