做一个简易新闻应用,程序在界面跳转时闪退,日志中报错如下
从日志中筛选关键句:
1,java.lang.RuntimeException:Unable to start activity ComponentInfo{com.example.news/com.example.news.NewsContentActivity}: android.view.InflateException: Binary XML file line #5: Binary XML file line #17: Attempt to invoke virtual method ‘boolean java.lang.String.equals(java.lang.Object)’ on a null object reference
(可知NewsContentActivity中加载的XML文件的第5行以及17行出错)
2,at com.example.news.NewsContentActivity.onCreate(NewsContentActivity.java:18)
可知NewsContentActivity.java的第18行出错(是加载布局的语句)
查看NewsContentActivity里加载的布局文件的第17行
错误在于View开头应当大写,改正后故障排除
最后吐槽一句,XML文件写错了,AS有时候不仅不报错,还把预览图正确的显示了,误导了不少人