您的位置:首页 > 移动开发 > Objective-C

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值
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐