java.lang.NullPointerException
at android.databinding.tool.store.LayoutFileParser.parseOriginalXml(LayoutFileParser.java:139)
line 1:0 mismatched input '?' expecting {COMMENT, SEA_WS, '<', PI}
解决方法 :
修改相关文件 : change UTF-8 BOM to UTF-8
Android studio , 选中文件 ,右键 ,remove BOM 即可
以下是参考资料:
BOM即byte order mark,具体含义可百度百科或维基百科,UTF-8文件中放置BOM主要是微软的习惯,但是放在别的系统上会出现问题。不含BOM的UTF-8才是标准形式,UTF-8不需要BOM带BOM的UTF-8文件的开头会有U+FEFF,所以我新建的空文件会有3字节的大小。
save it again with encoding UTF-8 rather than UTF-8 with BOM. I did this with Sublime Text.
Suffered the same problem for one day, finally found out the root cause. Andoid gradle plugin does not handle the encoding with Byte order mark (BOM) well. It is a encoding reading problem. If the file is saved in UTF-8 BOM format, Android gradle tool will detect the encoding as “UTF-8” with UniversalDetector library. The class android.databinding.tool.store.LayoutFileParser
will read like this:
InputStreamReader reader = new InputStreamReader(fin, “UTF-8”);
The first character returned by reader.read()
is 0xfeff
. Yes it is the ‘?’ in error message line 1:0 mismatched input '?' expecting {COMMENT, SEA_WS, '<', PI}
.
Refer the magic number of BOM at https://en.wikipedia.org/wiki/Byte_order_mark
How UniversalDetector works at http://chardet.readthedocs.io/en/latest/how-it-works.html