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
- TypeError:Cannot call method 'getItem' of null
- Cannot call method 'getItem' of null
- (启动H5本地存储)WebView显示网页出现Uncaught TypeError: Cannot call method 'getItem' of null异常
- (启动H5本地存储)WebView显示网页出现Uncaught TypeError: Cannot call method 'getItem' of null异常
- Chrome中canvas报Cannot call method 'getContext' of null
- Javascript Cannot call method 'appendChild' of null 解决方案
- 【ExtJS】Cannot call method 'removeCls'或'addCls' of null
- Android Webview: “Uncaught TypeError: Cannot read property 'getItem' of null”
- Uncaught TypeError: Cannot read property 'getItem' of null
- android webkit 加载js 出现 Error//webConsole:Uncaught Error:cannot call method ‘setItem’ of null at...
- Cannot call method 'indexOf' of undefined
- cannot call method foreach of undefined问题
- android webView 图片加载不出来 后台报错Uncaught TypeError: Cannot call method 'getElementsByTagName' of null
- 安卓Webview 加载网页 Uncaught TypeError: Cannot read property 'getItem' of null",
- Uncaught TypeError: Cannot call method 'substring' of undefined
- Extjs4---Uncaught TypeError: Cannot call method 'apply' of undefined
- Extjs4---Uncaught TypeError: Cannot call method 'substring' of undefined
- Extjs4---Uncaught TypeError: Cannot call method 'hasOwnProperty' of undefined
- tr td background
- Error Domain=NSURLErrorDomain Code=-1022
- 深入理解Semaphore
- 数据库索引
- 浏览器图标设置
- Cannot call method 'getItem' of null
- git https请求 提示error setting certificate verify locations
- Android Studio快捷键
- 爬虫历史简析
- 二叉堆的建立
- 局域网络访问问题及电脑控制手机显示
- 欢迎使用CSDN-markdown编辑器
- Linux各个目录的详解
- C++ 递归程序