Android 未捕获的类型错误:无法读取 null 的属性“tagName”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12510198/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught TypeError: Cannot read property 'tagName' of null
提问by Nicklas A.
We've been seeing this error in our web app the last couple of months:
过去几个月,我们一直在我们的 Web 应用程序中看到此错误:
Uncaught TypeError: Cannot read property 'tagName' of null
First I noticed it was only happening on android phones with 4.0.X, no other OS or version.
首先我注意到它只发生在 4.0.X 的安卓手机上,没有其他操作系统或版本。
To debug this I started by removing code and markup to try and find the culprit.
I did this until I had completely emptied the document of everything and the problem is still there.
为了调试这个,我首先删除代码和标记以尝试找到罪魁祸首。
我一直这样做,直到我完全清空了文档中的所有内容并且问题仍然存在。
The only clue is the console line before:
唯一的线索是之前的控制台行:
Reader :: Recognize :: INFO - Script is evaluating. recognizeArticle Start
Does anyone have any clue of why this is happening?
The problem is we get notified on errors and we can't ignore this since it's happening on a random line and page every time.
有没有人知道为什么会这样?
问题是我们会收到有关错误的通知,我们不能忽略这一点,因为它每次都发生在随机的行和页面上。
I can add that this happens on all our web apps.
我可以补充一点,这发生在我们所有的网络应用程序上。
To clarify, this is not a problem with our web app, the problem is with android.
I've removed ALL our code and markup and the problem is still there, android is doing something that causes this error.
澄清一下,这不是我们的网络应用程序的问题,而是 android 的问题。
我已经删除了我们所有的代码和标记,问题仍然存在,android 正在做一些导致这个错误的事情。
The phone I've tested on was a galaxy S3.
我测试过的手机是 Galaxy S3。
Since people don't seem to believe me when I say the source is empty:
因为当我说来源是空的时人们似乎不相信我:
(develop?) $ curl -v localhost:3000/us/app
* About to connect() to localhost port 3000 (#0)
* Trying 127.0.0.1...
* connected
* Connected to localhost (127.0.0.1) port 3000 (#0)
> GET /us/app HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:3000
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: text/html; charset=utf-8
< X-UA-Compatible: IE=Edge
< Cache-Control: no-cache
< X-Request-Id: c7d96d6898017b5efa7659028008a8b8
< X-Runtime: 0.011019
< Vary: Accept-Encoding
< Content-Length: 0
< Connection: keep-alive
< Server: thin 1.3.1 codename Triple Espresso
<
* Connection #0 to host localhost left intact
* Closing connection #0
采纳答案by Nicklas A.
I've found that on Android 4.0.X any page without a div containing at least 10 characters will throw a JavaScript error. The RSS reader apparently assumes that the page will have some content in a div.
我发现在 Android 4.0.X 上,任何没有包含至少 10 个字符的 div 的页面都会引发 JavaScript 错误。RSS 阅读器显然假定页面将在 div 中包含一些内容。
回答by user1122069
I have this error on Chrome for Linux and it was caused by the ImageBlocker extension. Since this "error" occurs for you when you launch a blank page, it reasons that you don't need to fix it. It is a bug with the browser or an extension.
我在 Linux 版 Chrome 上遇到此错误,它是由 ImageBlocker 扩展引起的。由于当您启动空白页面时会出现此“错误”,因此您无需修复它。这是浏览器或扩展程序的错误。
回答by Germann Arlington
Your question combined with your comments do NOTmake sense:
it sounds like you are opening emptypage containing no HTML or JavaScriptand it generates you an error???
您的问题与您的评论相结合是没有意义的:
听起来您正在打开不包含HTML 或 JavaScript 的空页面,并且它会生成一个错误???
There issome JavaScript function somewhere in your page that runs and
1) attempts to get some object from your DOM
2) fails to do 1) but does NOThandle the error leaving object reference variable set to NULL
3) attempts to use the above object variable to get it's tagName
property.
还有就是在你的页面的一些JavaScript函数某处运行,并
1)试图从你的DOM一些对象
2)未能做到1),但确实不处理错误留下对象引用变量设置为NULL
3)尝试使用上述对象变量来获取它的tagName
属性。
If the above were not true than you would NOThave an error to ask about.
如果上述情况不正确,那么您将不会有错误要问。