0

I need to reproduce a crash and I have to set the value of a FrameLayout to null.

I'm forced to work with kotlin synthetic extensions and use the xml view by it's Id.

Is there a way to set them as var instead of val so I can change their value?

petrrr33
  • 583
  • 9
  • 24
  • Can you try to return null in `onCreateView`? – cutiko Dec 27 '21 at 14:14
  • @cutiko I need only one child to be `null`, not the entire `view`. – petrrr33 Dec 27 '21 at 14:24
  • Can you clarify “forced to work with”? You cannot change them to reassignable `var`s. – Tenfour04 Dec 27 '21 at 14:31
  • In `onCreateView` before returning, after the layout is inflated, use that view to find the one you need null, and remove it from the parent. And then return that modified view. Something like this https://stackoverflow.com/a/6538694/4017501 – cutiko Dec 27 '21 at 14:35
  • I don't know what you try to achieve, but even if it were a var, setting it to null wouldn't do anything. It would still be inflated and part of your view hierarchy. You just wouldn't have a reference to it anymore. I have the feeling that what you are trying to do is not the right way to handle this crash – Ivo Dec 27 '21 at 14:51
  • @IvoBeckers I'm trying to reproduce the crash, not fix it. I'm trying to set a `view.visibility` attribute in a certain method on a `view` that sometimes is `null` and compare the logs. – petrrr33 Dec 27 '21 at 15:10
  • The synthetic properties return null when the current fragment’s view (if a view is attached) or activity’s content view doesn’t contain a view with the matching ID. – Tenfour04 Dec 27 '21 at 15:14

0 Answers0