4
我需要为9版或更高版本的设备使用CookieManager类。我的代码看起来像这样;如何在Android中向下兼容时使用新类?
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我调用这个方法检查os版本;
if (Build.VERSION.SDK_INT >= 9)
...
所以;在我的应用程序中,如果版本是2.2或更低;这种方法从未被调用过。我的问题是为什么我看到这个错误日志?
我删除'@TargetApi从你的代码(9)'和2.1模拟器上运行它,它工作没有任何错误。 – hasanghaforian
@hasanghaforian;它不会抛出异常,但是我提到了这个错误日志。你有看到它吗?你调试了应用程序还是只运行它? – syloc
我在logcat中没有错误地将它打散了。 – hasanghaforian