1

我是一名 Android 开发人员,并且是 JavaScript 新手。我正在使用 javascript 从我的活动中控制 webview。在我的登录页面中,当我使用 Java Script 函数时,我遇到了一些巨大的错误。请指导我避免这些错误。

代码:

web.loadUrl("javascript:document.getElementById(\"umail\").value = \""
        + email + "\";");
web.loadUrl("javascript:document.getElementById(\"password\").value = \""
        + pwd + "\";");
web.loadUrl("javascript:document.getElementById(\"confirmpassword\").value = \""
        + confirm_pwd + "\";");
web.loadUrl("javascript:func_register_step1('signin')");

web.loadUrl("javascript:window.JSInterface.getErrorMSG(document.getElementById('errormessagetd').innerHTML);");
web.loadUrl("javascript:window.JSInterface.getWarningMSG(document.getElementById('warning_msg').innerHTML);");

错误:

05-15 11:52:28.310: E/Web Console(3722): Uncaught TypeError: Cannot set property 'value' of null at null:1
05-15 11:52:28.310: E/Web Console(3722): Uncaught TypeError: Cannot set property 'value' of null at null:1
05-15 11:52:28.310: E/Web Console(3722): Uncaught TypeError: Cannot set property 'value' of null at null:1
05-15 11:52:28.310: E/Web Console(3722): Uncaught ReferenceError: func_register_step1 is not defined at null:1
05-15 11:52:28.310: E/Web Console(3722): Uncaught TypeError: Cannot read property 'innerHTML' of null at null:1
05-15 11:52:28.310: E/Web Console(3722): Uncaught TypeError: Cannot read property 'innerHTML' of null at null:1
05-15 11:52:31.240: E/Web Console(3722): Uncaught TypeError: Cannot set property 'value' of null at null:1
05-15 11:52:31.240: E/Web Console(3722): Uncaught TypeError: Cannot set property 'value' of null at null:1
05-15 11:52:31.240: E/Web Console(3722): Uncaught TypeError: Cannot set property 'value' of null at null:1
05-15 11:52:31.240: E/Web Console(3722): Uncaught ReferenceError: func_register_step1 is not defined at null:1
05-15 11:52:31.250: E/Web Console(3722): Uncaught TypeError: Cannot read property 'innerHTML' of null at null:1
05-15 11:52:31.250: E/Web Console(3722): Uncaught TypeError: Cannot read property 'innerHTML' of null at null:1
05-15 11:52:33.590: E/Web Console(3722): Uncaught TypeError: Cannot set property 'value' of null at null:1
05-15 11:52:33.590: E/Web Console(3722): Uncaught TypeError: Cannot set property 'value' of null at null:1
05-15 11:52:33.590: E/Web Console(3722): Uncaught TypeError: Cannot set property 'value' of null at null:1
05-15 11:52:33.590: E/Web Console(3722): Uncaught ReferenceError: func_register_step1 is not defined at null:1
05-15 11:52:33.600: E/Web Console(3722): Uncaught TypeError: Cannot read property 'innerHTML' of null at null:1
05-15 11:52:33.600: E/Web Console(3722): Uncaught TypeError: Cannot read property 'innerHTML' of null at null:1
05-15 11:52:40.260: E/Web Console(3722): Uncaught TypeError: Cannot set property 'value' of null at null:1
05-15 11:52:40.270: E/Web Console(3722): Uncaught TypeError: Cannot set property 'value' of null at null:1
05-15 11:52:40.270: E/Web Console(3722): Uncaught TypeError: Cannot set property 'value' of null at null:1
05-15 11:52:40.270: E/Web Console(3722): Uncaught ReferenceError: func_register_step1 is not defined at null:1
05-15 11:52:40.270: E/Web Console(3722): Uncaught TypeError: Cannot read property 'innerHTML' of null at null:1
05-15 11:52:40.270: E/Web Console(3722): Uncaught TypeError: Cannot read property 'innerHTML' of null at null:1
05-15 11:52:41.290: E/Web Console(3722): Uncaught TypeError: Cannot set property 'value' of null at null:1
05-15 11:52:41.290: E/Web Console(3722): Uncaught TypeError: Cannot set property 'value' of null at null:1
05-15 11:52:41.290: E/Web Console(3722): Uncaught TypeError: Cannot set property 'value' of null at null:1
05-15 11:52:41.290: E/Web Console(3722): Uncaught ReferenceError: func_register_step1 is not defined at null:1
05-15 11:52:41.290: E/Web Console(3722): Uncaught TypeError: Cannot read property 'innerHTML' of null at null:1
05-15 11:52:41.290: E/Web Console(3722): Uncaught TypeError: Cannot read property 'innerHTML' of null at null:1
4

1 回答 1

1

根据抛出的错误,似乎document.getElementById(...)返回null。因此应用.value.innerHTML为空抛出错误。

我怀疑当您调用 javascript 函数时该页面未加载。你什么时候调用你的javascript,我的意思是用哪种方法?为确保页面已加载,您可以调用对象loadUrlonPageFinished方法WebViewClient

于 2013-05-15T06:54:54.213 回答