在用Android WebView调用js时方法错误
2013-08-29 15:08
274 查看
1. Uncaught SyntaxError: Unexpected token ILLEGAL at :1
原因是在传值时少些了'',加上单引号及实现,如果不加单引号,传递值为int型时不会报错,但是传递String类型时会报错
webView.loadUrl("javascript:ChangeSize('"+textSize+"')");
javascript 中换行应用<Br>
传参数时若包含"\n"也会报以上错误,解决思路“\n” 换成" " 在js收到后
contentString =contentString.replace(/ /g,"<br>"); 空格换成<Br>
或者在传的时候“\n” rq dn <Br>
2. java.lang.NumberFormatException: null
例子:int value = Integer.valueOf(str).intValue();或者是 int value = Integer.parseInt(str);
如果str为null,则出现java.lang.NumberFormatException: null的错误,解决方法如下:
int value = 0;
if (str != null)
value = Integer.valueOf(str).intValue();
else
{
.... //可以为value赋默认值
}
3. Uncaught ReferenceError: {某个js的方法,例如:toImg} is not defined
该错误我也不知道,反正呢解决了一些其他错误,该错误也就消失了。
总之,在做webview调用js的时候一定要注意,很多都是一个不小心就错了,写的时候还是仔细认真点吧,毕竟调来调去的很容易就忽略一些简单容易的,然后就犯一些低级错误。。。
原因是在传值时少些了'',加上单引号及实现,如果不加单引号,传递值为int型时不会报错,但是传递String类型时会报错
webView.loadUrl("javascript:ChangeSize('"+textSize+"')");
javascript 中换行应用<Br>
传参数时若包含"\n"也会报以上错误,解决思路“\n” 换成" " 在js收到后
contentString =contentString.replace(/ /g,"<br>"); 空格换成<Br>
或者在传的时候“\n” rq dn <Br>
2. java.lang.NumberFormatException: null
例子:int value = Integer.valueOf(str).intValue();或者是 int value = Integer.parseInt(str);
如果str为null,则出现java.lang.NumberFormatException: null的错误,解决方法如下:
int value = 0;
if (str != null)
value = Integer.valueOf(str).intValue();
else
{
.... //可以为value赋默认值
}
3. Uncaught ReferenceError: {某个js的方法,例如:toImg} is not defined
该错误我也不知道,反正呢解决了一些其他错误,该错误也就消失了。
总之,在做webview调用js的时候一定要注意,很多都是一个不小心就错了,写的时候还是仔细认真点吧,毕竟调来调去的很容易就忽略一些简单容易的,然后就犯一些低级错误。。。
相关文章推荐
- android webView调用js函数的几种方法
- Android WebView使用方法详解 附js交互调用方法
- Android 安卓webview调用js的方法,调用不了,失败及其原因
- WebView之js调用Android类的方法传递数据
- JS 调用IOS Android webview方法
- webView中js调用android方法一调用程序就退出是怎么回事
- WebView加载html代码,js脚本中调用android对象的方法...
- Android webview和js互相调用实现方法
- android之通过webview实现与js方法相互调用,数据交互
- 安卓与JS互调之android webview addJavascriptInterface 的方法不能调用
- android中webview携带cookie以及webview所加载网页中js调用java方法问题
- webview通过js调用android方法
- Android调用WebView的JS和JS调用Android的方法
- Android WebView详解之JS调用Java方法
- ANDROID WEBVIEW和JAVASCRIPT交互_JS调用ANDROID方法
- android中webview调用js方法,js调用java方法
- Android WEBVIEW中调用<a href>的问题!!!不是js的方法
- 【Js】调用Android WebView定义的方法总结
- WebView之js调用Android类的方法传递数据
- android中webView JS调用Android的方法、webView的下拉刷新(SwipeRefreshLayout)、下载文件