java.lang.IllegalStateException:需要在CookieSyncManager :: getInstance()之前调用CookieSyncManager :: createInstance()

时间:2013-07-31 09:40:21

标签: android cookies android-webview webviewclient

我想在shouldOverrideUrlLoading()方法的webview中获取cookie,我收到了这个错误。请看下面的代码,

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
        }
 }

我得到了这个错误,

java.lang.IllegalStateException: CookieSyncManager::createInstance() needs to be called before CookieSyncManager::getInstance()

1 个答案:

答案 0 :(得分:1)

在活动的CookieSyncManager.createInstance(this);方法中使用onCreate()。错误显然需要在调用createInstance()之前调用getInstance()