2

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);
ThinkingMonkey
  • 12,539
  • 13
  • 57
  • 81
Jessie A. Morris
  • 2,267
  • 21
  • 23

1 Answers1

8

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!

Daniel DiPaolo
  • 55,313
  • 14
  • 116
  • 115
CodegistCRest
  • 724
  • 3
  • 9
  • Thank you! I am new to Java, and didn't realize the difference between interfaces and classes. I also see the known implementations which will be insanely useful. :-) – Jessie A. Morris Jan 10 '11 at 21:48