From 1a7c149311ac67715204fa0216c422b511fd02c0 Mon Sep 17 00:00:00 2001 From: Shai Almog <67850168+shai-almog@users.noreply.github.com> Date: Tue, 3 Oct 2023 05:36:33 +0300 Subject: [PATCH] Attempted fix for #3164 a random NPE in Android --- .../impl/android/AndroidAsyncView.java | 75 +++++-------------- 1 file changed, 18 insertions(+), 57 deletions(-) diff --git a/Ports/Android/src/com/codename1/impl/android/AndroidAsyncView.java b/Ports/Android/src/com/codename1/impl/android/AndroidAsyncView.java index ead3f79d3f..619a59779d 100644 --- a/Ports/Android/src/com/codename1/impl/android/AndroidAsyncView.java +++ b/Ports/Android/src/com/codename1/impl/android/AndroidAsyncView.java @@ -332,22 +332,24 @@ public void resizeViews() { if(children > 0) { for (int iter = 0; iter < children; iter++) { final View v = getChildAt(iter); - final AndroidAsyncView.LayoutParams lp = (AndroidAsyncView.LayoutParams) v.getLayoutParams(); - if (lp.dirty) { - lp.dirty = false; - v.post(new Runnable() { - @Override - public void run() { - v.requestLayout(); - - Display.getInstance().getInstance().callSerially(new Runnable() { - @Override - public void run() { - Display.getInstance().getCurrent().repaint(); - } - }); - } - }); + if(v != null) { + final AndroidAsyncView.LayoutParams lp = (AndroidAsyncView.LayoutParams) v.getLayoutParams(); + if (lp.dirty) { + lp.dirty = false; + v.post(new Runnable() { + @Override + public void run() { + v.requestLayout(); + + Display.getInstance().getInstance().callSerially(new Runnable() { + @Override + public void run() { + Display.getInstance().getCurrent().repaint(); + } + }); + } + }); + } } } } @@ -426,47 +428,6 @@ public void run() { } int children = getChildCount(); - if(children > 0) { - com.codename1.ui.Form c = Display.getInstance().getCurrent(); - for (int iter = 0; iter < children; iter++) { - final View v = getChildAt(iter); - final AndroidAsyncView.LayoutParams lp = (AndroidAsyncView.LayoutParams) v.getLayoutParams(); - //if (lp != null && c == lp.pc.getComponentForm()) { - //v.postInvalidate(); - - /*if(lp.dirty) { - lp.dirty = false; - v.post(new Runnable() { - @Override - public void run() { - if (v.getVisibility() == View.INVISIBLE) { - v.setVisibility(View.VISIBLE); - } - v.requestLayout(); - } - }); - } else { - if (v.getVisibility() == View.INVISIBLE) { - v.post(new Runnable() { - @Override - public void run() { - v.setVisibility(View.VISIBLE); - } - }); - } - }*/ - //} else { - /*if(v.getVisibility() == View.VISIBLE) { - v.post(new Runnable() { - @Override - public void run() { - v.setVisibility(View.INVISIBLE); - } - }); - }*/ - //} - } - } if (rect == null) { postInvalidate(); } else {