0

I used Fragments in my small project (i know ... fragments are weird) and I recently implemented Firebase to my project. I saw crash on Android 7.0 device with weird exception without any hint on what was a cause. I checked row from exception, but its simple EditText initialization and creating Toast. My only guess is that context was null, but then it should not be executed, because it was wrapped in ?.let function.

Anyone experienced this exception before?

java.lang.IllegalStateException: 
  at androidx.fragment.app.Fragment.requireContext (Fragment.java:696)
  at androidx.fragment.app.Fragment.getResources (Fragment.java:760)
  at androidx.fragment.app.Fragment.getString (Fragment.java:782)
  at online.myproject.myproject.fragments.entityCreationFragments.ExtEntityFragment$createNewExtEntity$$inlined$let$lambda$1.invoke (ExtEntityFragment.kt:322)

Row 322 is this code:

context?.let { c -> createToast(getString(R.string.object_creation_success), c)}
martin1337
  • 2,238
  • 5
  • 27
  • 66
  • Can be useful [thread](https://stackoverflow.com/questions/47250787/android-support-library-27-fragment-update) – M D Jul 11 '19 at 06:59
  • It's the `getString()` call and not `context`. However if `context` in your code is the kotlin syntax sugar for `getContext()` and it's not null, then `requireContext()` should not throw here. – laalto Jul 11 '19 at 07:04
  • Yes, context is getContext(). Really weird error – martin1337 Jul 12 '19 at 06:14

0 Answers0