簡體   English   中英

在Android中調用Javascript函數時未捕獲到TypeError

[英]Uncaught TypeError when calling a Javascript Function in Android

我是一名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

根據引發的錯誤,似乎document.getElementById(...)返回null。 因此,將.value.innerHTML應用於null會引發錯誤。

我懷疑您調用javascript函數時頁面未加載。 您什么時候調用javascript,我的意思是哪種方法? 為確保頁面已加載,可以在WebViewClient對象的onPageFinished方法中調用loadUrl

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM