3
我想在webview onOverrideUrlLoading()方法中獲取cookie,並且出現此錯誤。請各位看看下面我的代碼,java.lang.IllegalStateException:需要在CookieSyncManager :: getInstance()之前調用CookieSyncManager :: createInstance()
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()
我也看到了同樣的錯誤。我在onCreate方法中調用了CookieSyncManager.createInstance(this),在onResume中調用了CookieSyncManager.getInstance()。startSync()和onPause中的CookieSyncManager.getInstance()。stopSync()。我仍然有時會看到相同的錯誤 – aasha