Attempt to read from field 'int android.graphics.Rect.bottom' on a null object reference
2017-06-24 14:50
603 查看
22881 22881 E AndroidRuntime: java.lang.NullPointerException: Attempt to read from field 'int android.graphics.Rect.bottom' on a null object reference 22881 22881 E AndroidRuntime: at com.xxx.xxx.TouchableImageSpan.draw(TouchableImageSpan.java:122) 22881 22881 E AndroidRuntime: at android.text.TextLine.handleReplacement(TextLine.java:825) 22881 22881 E AndroidRuntime: at android.text.TextLine.handleRun(TextLine.java:908) 22881 22881 E AndroidRuntime: at android.text.TextLine.drawRun(TextLine.java:368) 22881 22881 E AndroidRuntime: at android.text.TextLine.draw(TextLine.java:196)
NullPointerException 是 bottom 为null?
@Override public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) { mLeft = (int) x; mBottom = bottom; BitmapDrawable cachedBmp = getCachedDrawable(); canvas.save(); int i = bottom - nBounds.bottom; }
分析了一下, 这里怎么可能为null , int 的 bottom
ImageSpan draw 方法前会执行什么, 什么时候 draw —–按理说是 new 完了以后,show的时候 draw
最后看到了是在 某些特殊的情况下,导致图片不存在,但是记录的图片是存在的, (我这边是 adb shell 进入删除files 文件夹下的文件)
最后找了好久发现代码在判断 file.exits() 为 true 中 对 nBounds 做了初始化, 但是 不存在却没对 nBounds 做了初始化
所以以后应该关注的点是绝对不是 int值
相关文章推荐
- Attempt to read from field 'int android.view.View.mViewFlags' on a null object reference
- Attempt to read from field 'int android.view.View.mViewFlags' on a null object reference
- 解决java.lang.NullPointerException Attempt to read from field 'int android.view.View.mViewFlags' on a
- Attempt to invoke virtual method 'void android.app.ActionBar.hide()' on a null object reference
- Attempt to invoke virtual method 'void android.app.ActionBar.hide()' on a null object reference
- Android SearchView android.graphics.drawable..Drawable.setState(int[])' on a null object reference
- 关于Attempt to invoke virtual method 'HSSFCell.getCellType(int)'' on a null object reference
- Attempt to invoke virtual method 'int java.lang.Object.hashCode()' on a null object reference(Fb)
- 'int android.graphics.Bitmap.getWidth()' on a null object reference
- [Android] android.app.Activity.findViewById(int) on a null object reference
- Attempt to invoke virtual method 'void android.graphics.drawable.Drawable.setAlpha(int)' on a null o
- Android开发中出现Attempt to invoke virtual method...on a null object reference
- Attempt to invoke virtual method 'void android.graphics.drawable.Drawable.setAlpha(int)' on a null o
- android.view.View android.view.View.findViewById(int)' on a null object reference
- void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
- 解决Attempt to invoke virtual method '...ListAdapter'on a null object reference
- java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getImportant
- java.lang.NullPointerException:Attempt to invoke virtual method xxx on a null object reference
- android.support.v4.app.FragmentHostCallback.getHandler()' on a null object reference
- oid android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference的解决