android.view.View android.view.View.findViewById(int)' on a null object reference
2017-11-30 17:23
806 查看
突然出现这样的错误
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
只在vivo 和乐视手机出现这种情况,以为是机型问题。
追查原因发现,
![](https://oscdn.geek-share.com/Uploads/Images/Content/202011/28/38f840b9fa7b573e59120f8366a7b8de)
rootview初始化这行不执行。仔细跟下日志,发现是
W/ResourceType(7881): No known package when getting value for resource number 0xffffffff
确定时布局里的资源文件引起的,开始查看布局里的每一个控件和属性。
![](https://oscdn.geek-share.com/Uploads/Images/Content/202011/28/be124787e30214ad7ee6e6dd43494ec0)
在FloatingActionButton里我用了backgroundTint属性,这个属性仅用在api21及以上,项目最低是15。
正好vivo和乐视手机的安卓系统是低于21的安卓版本,所以会造成这样的问题。
但是log和错误太不明显了,让人起初根本摸不着头脑,而且容易带偏,以为是机型问题,瞎找一通。
希望遇到此问题的人能不被绕晕。
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
只在vivo 和乐视手机出现这种情况,以为是机型问题。
追查原因发现,
rootview初始化这行不执行。仔细跟下日志,发现是
W/ResourceType(7881): No known package when getting value for resource number 0xffffffff
确定时布局里的资源文件引起的,开始查看布局里的每一个控件和属性。
在FloatingActionButton里我用了backgroundTint属性,这个属性仅用在api21及以上,项目最低是15。
正好vivo和乐视手机的安卓系统是低于21的安卓版本,所以会造成这样的问题。
但是log和错误太不明显了,让人起初根本摸不着头脑,而且容易带偏,以为是机型问题,瞎找一通。
希望遇到此问题的人能不被绕晕。
相关文章推荐
- [Android] android.app.Activity.findViewById(int) on a null object reference
- Android SearchView android.graphics.drawable..Drawable.setState(int[])' on a null object reference
- findViewById出现错误View.isRootNamespace()' on a null object reference
- Attempt to read from field 'int android.view.View.mViewFlags' on a null object reference
- 'int android.graphics.Bitmap.getWidth()' on a null object reference
- void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
- Attempt to read from field 'int android.view.View.mViewFlags' on a null object reference
- void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
- Attempt to read from field 'int android.graphics.Rect.bottom' on a null object reference
- oid android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference的解决
- Android application - findViewById返回NULL的问题
- 【android中findViewById返回控件指针为NULL】
- 刚学Android遇到的问题 findViewById值为null(新版本)
- Android开发:findViewById返回null的解决办法
- Attempt to invoke virtual method 'int java.lang.Object.hashCode()' on a null object reference(Fb)
- android findViewById 返回 null
- android.support.v4.app.FragmentHostCallback.getHandler()' on a null object reference
- android:通过findViewById试图获取界面元素对象为Null,运行会提示空指针异常
- android开发之自定义控件时findViewById方法返回null的解决方法
- Android 自定义控件布局 NullPointerException findViewById