TypeError:Cannot call method 'getItem' of null
来源:互联网 发布:传智播客 c语言 编辑:程序博客网 时间:2024/05/24 22:42
这个错误是我在android中使用webview打开一个带有发送短信的html5页面,发送短信报的错误,发送短信我使用的是leancloud提供了一套手机短信验证
<span style="font-size:14px;">AV.Cloud.requestSmsCode({ mobilePhoneNumber : mb, name : 'XXXX, op : '手机绑定验证', ttl : 2 }).then(function() { //发送成功 getCode(document.getElementById("getCheckCode")); }, function(err) { if(err.code==127){ alert("请输入正确的手机号码!"); }else if(err.code==601){ alert("发送短信过于频繁,请稍后再试!"); }else{ //发送失败 alert("验证码获取失败,请稍后再试!"); } });</span>
然而在调用这个方法的时候一直报TypeError:Cannot call method 'getItem' of null,但是在PC端测试是没有问题的,
然后我找到那行错误的地方,localStorage.getItem,是使用Dom的本地存储机制,那么可能最大的问题就是在webview没开启DOM storage的问题,果然经过多方查证,原来这个默认是不开启DOM storage,导致后面在使用的时候找不到而报错。
/** * Sets whether the DOM storage API is enabled. The default value is false. * * @param flag true if the WebView should use the DOM storage API */public abstract void setDomStorageEnabled(boolean flag);
<span style="font-size:14px;"> WebSettings settings = webView.getSettings(); settings.setDomStorageEnabled(true);</span>
这样问题就解决了,又死掉了好多脑细胞!!!!
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异常
- Android Webview: “Uncaught TypeError: Cannot read property 'getItem' of null”
- Uncaught TypeError: Cannot read property 'getItem' 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
- Uncaught TypeError: Cannot call method 'substring' of undefined
- Uncaught TypeError: Cannot call method 'replace' of undefined 的解决
- Uncaught TypeError: Cannot call method 'substring' of undefined
- Extjs4---Uncaught TypeError: Cannot call method 'hasOwnProperty' of undefined
- JsBridge "Uncaught TypeError: Cannot call method 'callHandler' of undefined", source
- android webView 图片加载不出来 后台报错Uncaught TypeError: Cannot call method 'getElementsByTagName' of null
- Chrome中canvas报Cannot call method 'getContext' of null
- TableView详细解释
- Linux协议栈accept和syn队列问题
- 定时器的另一种初始化方法
- POJ 1090 Chain
- tabbaritem设置红点大小、自定义宽高
- TypeError:Cannot call method 'getItem' of null
- RealSense 开发(一):深度图像获取
- 怎么样终止一个线程呢?
- 用Redis构建分布式锁
- 论文笔记 《Selective Search for Object Recognition》
- 清除网页float浮动影响
- 序列化:json_encode/json_decode 与 serialize/unserialize
- 浅入浅出理解傅里叶变换
- Mysql主从复制