Skip to content

Commit 7064aa0

Browse files
graycreateclaude
andauthored
fix: add null checks in HtmlMovementMethod to prevent crashes (#108)
- Add null check for imgs collection before iterating - Add null check for currentImg before comparison - Add null check for imgs.get(i) and its getUrl() method - Prevents NullPointerException when clicking on image spans - Fixes crash reported in Google Play Console at line 215 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent cc8a7cd commit 7064aa0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

app/src/main/java/me/ghui/v2er/widget/richtext/HtmlMovementMethod.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,14 @@ private void onSpanClick(CharacterStyle span) {
211211
} else if (span instanceof ImageSpan) {
212212
String currentImg = ((ImageSpan) span).getSource();
213213
int index = 0;
214-
for (int i = 0; i < imgs.size(); i++) {
215-
if (currentImg.equals(imgs.get(i).getUrl())) {
216-
index = i;
217-
break;
214+
// Add null checks to prevent NullPointerException
215+
if (imgs != null && currentImg != null) {
216+
for (int i = 0; i < imgs.size(); i++) {
217+
String imgUrl = imgs.get(i) != null ? imgs.get(i).getUrl() : null;
218+
if (currentImg.equals(imgUrl)) {
219+
index = i;
220+
break;
221+
}
218222
}
219223
}
220224
ImagesInfo imagesInfo = new ImagesInfo(index, imgs);

0 commit comments

Comments
 (0)