我是靠谱客的博主 糊涂项链,这篇文章主要介绍Attempt to read from field 'int android.graphics.Rect.bottom' on a null object reference,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
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?

复制代码
1
2
3
4
5
6
7
8
9
10
11
@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.graphics.Rect.bottom' on a null object reference的全部内容,更多相关Attempt内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(90)

评论列表共有 0 条评论

立即
投稿
返回
顶部