Creating a new cookie in Android

Jessie A. Morris picture Jessie A. Morris · Jan 10, 2011 · Viewed 8.5k times · Source

I want to create a new Cookie in Android. When I do:

Cookie testCookie = new Cookie();

I get an error saying, "Cannot instantiate the type Cookie". All I want to do is create a new cookie and stick it into a cookie store (uses org.apache.http.client CookieStore not java.net.CookieStore or what not). I cannot use HttpCookie because I cannot cast it to a Cookie. Any thoughts here?

Edit (Additional Code):

Here's more or less what I want to do:

import org.apache.http.client.CookieStore;
import org.apache.http.cookie.Cookie;
import java.net.CookieManager;

CookieManager manager = new CookieManager();
CookieStore store = (CookieStore) manager.getCookieStore();

Cookie testCookie = new Cookie();

store.addCookie(testCookie);

Answer

CodegistCRest picture CodegistCRest · Jan 10, 2011

Cookie, if what you're talking about is org.apache.http.cookie.Cookie, is an Interface and thus cannot be directly instantiated.

Looked at the doc here http://developer.android.com/reference/org/apache/http/cookie/Cookie.html for any known implementation of it, I guess org.apache.http.impl.cookie.BasicClientCookie would do it!