Cannot call method 'getItem' of null

来源:互联网 发布:feel软件 编辑:程序博客网 时间:2024/05/18 22:44

问题

项目时一个APP的外壳,在WebView中嵌入html5页面。我在h5中操作localStorage 来缓存数据,但是程序一到localStorage.getItme()就报错执行不下去。

寻找线索

localStorage.getItme()进行了try catch看错误信息:
Cannot call method 'getItem' of null 似乎是不支持localStorage的操作。但是其他页面的localStorage 操作没有问题呀?是不是安卓那边的原因?

原因

后来在stackoverflow找到答案
是安卓那边没有给当前的这个webview开启缓存权限。坑爹( ⊙ o ⊙ )啊!

WebSettings settings = webView.getSettings();settings.setDomStorageEnabled(true);

改用cookie

没办法,最后改用cookie来存数据。
cookie的操作方法

0 0