我需要为 9 或更高版本的设备使用 CookieManager 类。我的代码看起来像这样;
public class HttpUtils {
private static CookieManager cookie_manager = null;
@TargetApi(9)
public static CookieManager getCookieManager() {
if (cookie_manager == null) {
cookie_manager = new CookieManager();
CookieHandler.setDefault(cookie_manager);
}
return cookie_manager;
}
}
当我在 2.2 模拟器上运行它时;我有这个错误日志;
Could not find class 'java.net.CookieManager', referenced from method com.application.utils.HttpUtils.getCookieManager
当我需要 CookieManager 时,我会通过检查操作系统版本来调用此方法;
if (Build.VERSION.SDK_INT >= 9)
...
所以; 如果版本为 2.2 或更低,则在我的应用中;这个方法永远不会被调用。我的问题是为什么我会看到这个错误日志?