我想在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()
答案 0 :(得分:1)
在活动的CookieSyncManager.createInstance(this);
方法中使用onCreate()
。错误显然需要在调用createInstance()
之前调用getInstance()
。