工作中遇到的問題(持續更新)
阿新 • • 發佈:2018-12-10
1 在三星手機上出現這個問題,其他手機沒發現問題。
java.lang.IllegalStateException: Call CookieSyncManager::createInstance() or create a webview before using this class 清除Cookie或者獲取Cookie前,首先同步。
報錯程式碼:
public String getCookies(Context context, String domain, String key){ //獲取Cookie CcookieManager cookieManager = CookieManager.getInstance(); String cookie = cookieManager.getCookie(domain); return cookie; }
修改後:[清除Cookie前,首先同步]
public String getCookies(Context context, String domain, String key){ //首先同步Cookie CookieSyncManager cookieSyncManager = CookieSyncManager .createInstance(context); cookieSyncManager.startSync(); cookieSyncManager.sync(); //獲取Cookie CookieManager cookieManager = CookieManager.getInstance(); String cookie = cookieManager.getCookie(domain); return cookie; }
參考:[Android清除cookie報錯java.lang.IllegalStateException: Call CookieSyncManager::createInstance() or create a webview before using this class]